public CacheItem(ComparableBytesAbstract DesiredLookupKey, IHashable CacheValue, TimeSpan ExpireIn) { Key = DesiredLookupKey.Bytes; Value = CacheValue; ExpireDate = DateTime.Now.Add(ExpireIn); AddedDate = DateTime.Now; }
public override bool AddOrUpdate <T>(ComparableBytesAbstract Key, T Value, TimeSpan ExpireSpan) { CountWrite(); CacheItem newItem = new CacheItem(Key, Value, ExpireSpan); return(AddOrUpdate(newItem)); }
public override CacheItem Get(ComparableBytesAbstract Key) { CountRead(); var item = new CacheItem(); Cache.TryGetValue(Key, out item); return(item); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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)); }
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); } }
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); }
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)); }
public Peer GetPeer(ComparableBytesAbstract Key) { throw new NotImplementedException(); }
public abstract bool Exists(ComparableBytesAbstract Key);
public static int Compare(byte[] Left, ComparableBytesAbstract Right) { return(Compare(Left, Right.Bytes)); }
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)); }
public override bool Exists(ComparableBytesAbstract Key) { CountRead(); return(Cache.ContainsKey(Key)); }
public override CacheItem Get(ComparableBytesAbstract Key) { CountRead(); return(LCol.FindOne(x => x.Key == Key.Bytes)); }
public abstract T Get <T>(ComparableBytesAbstract Key) where T : IHashable;
public abstract bool AddOrUpdate <T>(ComparableBytesAbstract Key, T Value, TimeSpan ExpireSpan) where T : IHashable;
public abstract CacheItem Get(ComparableBytesAbstract Key);
public override bool Exists(ComparableBytesAbstract Key) { CountRead(); return(LCol.Exists(x => x.Key == Key.Bytes)); }
public abstract bool Remove(ComparableBytesAbstract Key);