Example #1
0
 public CacheItem(ComparableBytesAbstract DesiredLookupKey, IHashable CacheValue, TimeSpan ExpireIn)
 {
     Key        = DesiredLookupKey.Bytes;
     Value      = CacheValue;
     ExpireDate = DateTime.Now.Add(ExpireIn);
     AddedDate  = DateTime.Now;
 }
Example #2
0
        public override bool AddOrUpdate <T>(ComparableBytesAbstract Key, T Value, TimeSpan ExpireSpan)
        {
            CountWrite();
            CacheItem newItem = new CacheItem(Key, Value, ExpireSpan);

            return(AddOrUpdate(newItem));
        }
Example #3
0
        public override CacheItem Get(ComparableBytesAbstract Key)
        {
            CountRead();
            var item = new CacheItem();

            Cache.TryGetValue(Key, out item);
            return(item);
        }
Example #4
0
        /// <summary>
        /// Gets an item in this cache
        /// </summary>
        /// <param name="Key">Item Key</param>
        /// <param name="Recurse">If true, also searches all OverflowCaches</param>
        /// <returns>The object or null</returns>
        public CacheItem Get(ComparableBytesAbstract Key, bool Recurse)
        {
            var g = Get(Key);

            if (Recurse && g == null && OverflowCache != null)
            {
                return(OverflowCache.Get(Key, Recurse));
            }

            return(g);
        }
Example #5
0
        /// <summary>
        /// Gets an item in this cache
        /// </summary>
        /// <param name="Key">Item Key</param>
        /// <param name="Recurse">If true, also searches all OverflowCaches</param>
        /// <returns>The object or null</returns>
        public T Get <T>(ComparableBytesAbstract Key, bool Recurse) where T : IHashable
        {
            var g = Get <T>(Key);

            if (g == null && OverflowCache != null)
            {
                return(OverflowCache.Get <T>(Key, Recurse));
            }

            return(g);
        }
Example #6
0
        /// <summary>
        /// Removes an item from this cache
        /// </summary>
        /// <param name="Key">Item Key</param>
        /// <param name="Recurse">If true, also searches all OverflowCaches</param>
        /// <returns>True if the item was removed</returns>
        public bool Remove(ComparableBytesAbstract Key, bool Recurse)
        {
            var g = Remove(Key);

            if (Recurse && g == false && OverflowCache != null)
            {
                return(OverflowCache.Remove(Key, Recurse));
            }

            return(g);
        }
Example #7
0
        /// <summary>
        /// Checks if a key exists in this cache
        /// </summary>
        /// <param name="Key">Item Key</param>
        /// <param name="Recurse">If true, also searches all OverflowCaches</param>
        /// <returns>True if the object exists</returns>
        public bool Exists(ComparableBytesAbstract Key, bool Recurse)
        {
            bool e = Exists(Key);

            if (Recurse && e == false && OverflowCache != null)
            {
                return(OverflowCache.Exists(Key, Recurse));
            }

            return(e);
        }
Example #8
0
        public override bool Remove(ComparableBytesAbstract Key)
        {
            CountWrite();
            var deletes = LCol.Delete(x => x.Key == Key.Bytes);

            if (deletes > 0)
            {
                //CurrentCollectionCount -= deletes;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static int Compare(ComparableBytesAbstract Left, ComparableBytesAbstract Right)
        {
            if (ReferenceEquals(Right, null) && ReferenceEquals(Left, null))
            {
                return(0);
            }
            else if (ReferenceEquals(Right, null))
            {
                return(-1);
            }
            else if (ReferenceEquals(Left, null))
            {
                return(1);
            }

            return(Compare(Left.Bytes, Right.Bytes));
        }
Example #10
0
        public override bool Remove(ComparableBytesAbstract Key)
        {
            CountWrite();
            var c = new CacheItem();

            Cache.TryRemove(Key, out c);

            if (c?.Value != null)
            {
                _currentCollectionCount -= 1;
                CurrentCollectionSize   -= c.Value.ComputedHash.SourceByteLength;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        public T Get <T>(ComparableBytesAbstract Key) where T : Hashable
        {
            if (StoreCache.Exists(Key))
            {
                return(StoreCache.Get <T>(Key));
            }
            else
            {
                //try and get from the closest peer
                if (KnownPeers.NodeCount > 0)
                {
                    var closestPeer = GetPeer(Key);

                    if (closestPeer != null)
                    {
                        return(closestPeer.TryGet <T>(Key));
                    }
                }
            }

            return(null);
        }
Example #12
0
        public override T Get <T>(ComparableBytesAbstract Key)
        {
            var item = Get(Key);

            return((T)item.Value);
        }
 public static int Compare(ComparableBytesAbstract Left, byte[] Right)
 {
     return(Compare(Left.Bytes, Right));
 }
Example #14
0
 public Peer GetPeer(ComparableBytesAbstract Key)
 {
     throw new NotImplementedException();
 }
Example #15
0
 public abstract bool Exists(ComparableBytesAbstract Key);
 public static int Compare(byte[] Left, ComparableBytesAbstract Right)
 {
     return(Compare(Left, Right.Bytes));
 }
Example #17
0
        public T TryGet <T>(ComparableBytesAbstract Key) where T : Hashable
        {
            var transport = GetTransport();

            return(transport.TryGet <T>(Key));
        }
 public int CompareTo(ComparableBytesAbstract HashObject)
 {
     return(Compare(this.Bytes, HashObject.Bytes));
 }
Example #19
0
 public override bool Exists(ComparableBytesAbstract Key)
 {
     CountRead();
     return(Cache.ContainsKey(Key));
 }
Example #20
0
 public override CacheItem Get(ComparableBytesAbstract Key)
 {
     CountRead();
     return(LCol.FindOne(x => x.Key == Key.Bytes));
 }
Example #21
0
 public abstract T Get <T>(ComparableBytesAbstract Key) where T : IHashable;
Example #22
0
 public abstract bool AddOrUpdate <T>(ComparableBytesAbstract Key, T Value, TimeSpan ExpireSpan) where T : IHashable;
Example #23
0
 public abstract CacheItem Get(ComparableBytesAbstract Key);
Example #24
0
 public override bool Exists(ComparableBytesAbstract Key)
 {
     CountRead();
     return(LCol.Exists(x => x.Key == Key.Bytes));
 }
Example #25
0
 public abstract bool Remove(ComparableBytesAbstract Key);