Esempio n. 1
0
        public void Put(VolumePagePtr pPage, PageInfo info, ArraySegment <byte> content)
        {
            EnsureObjectNotDisposed();
            if (!Enabled)
            {
                return;
            }

            var tbl  = getVolumeTable(pPage.VolumeId);
            var item = new _entry
            {
                Info = info,
                Data = new byte[content.Count]
            };

            Array.Copy(content.Array, content.Offset, item.Data, 0, content.Count);

            int?maxAge = LifeTimeSec;

            if (maxAge.Value <= 0)
            {
                maxAge = null;
            }

            //since pageId can not be less than 1 we use negative pageIds for storing PageInfo without the byte array
            tbl.Put(pPage.PageId, item, maxAge);  //store the full item
            tbl.Put(-pPage.PageId, info, maxAge); //store just the pageInfo with reverse index
        }
Esempio n. 2
0
        public bool Contains(VolumePagePtr pPage)
        {
            EnsureObjectNotDisposed();
            if (!Enabled)
            {
                return(false);
            }
            var tbl = getVolumeTable(pPage.VolumeId);

            return(tbl.ContainsKey(pPage.PageId));
        }
Esempio n. 3
0
        public bool TryGet(VolumePagePtr pPage, out PageInfo info)
        {
            EnsureObjectNotDisposed();
            if (!Enabled)
            {
                info = default(PageInfo);
                return(false);
            }

            var tbl    = getVolumeTable(pPage.VolumeId);
            var cached = tbl.Get(-pPage.PageId);//the pageInfo is stored with flipped pageId

            if (cached is PageInfo pi)
            {
                info = pi;
                return(true);
            }

            info = default(PageInfo);
            return(false);
        }
Esempio n. 4
0
        public bool TryGet(VolumePagePtr pPage, MemoryStream pageData, out PageInfo info)
        {
            EnsureObjectNotDisposed();
            if (!Enabled)
            {
                info = default(PageInfo);
                return(false);
            }

            var tbl    = getVolumeTable(pPage.VolumeId);
            var cached = tbl.Get(pPage.PageId) as _entry;

            if (cached == null)
            {
                info = default(PageInfo);
                return(false);
            }

            info = cached.Info;
            pageData.Write(cached.Data, 0, cached.Data.Length);
            return(true);
        }