public override CacheEntry Get(object[] args) { string hash = GetHash(args); Debug.WriteLine($"Getting hash: {hash}"); if (!LastIndexCache.ContainsKey(hash)) { return(null); } int lastIndex = LastIndexCache[hash]; var entry = ValueLists[lastIndex]; if (lastIndex > 0) { MoveToFrontOfCache(entry); } else { Debug.WriteLine($"Hash was already the most recently used. Will not move: {entry.Hash}"); Debug.WriteLine( $"Current state:{Environment.NewLine}" + $"Indices: {JsonConvert.SerializeObject(LastIndexCache)}{Environment.NewLine}" + $"Cache: {JsonConvert.SerializeObject(ValueLists)}" ); } Debug.WriteLine($"Returning existing entry: {entry.Hash}"); return(entry); }
public override bool Add(object[] args, object result) { string hash = GetHash(args); if (LastIndexCache.ContainsKey(hash)) { return(false); } Debug.WriteLine($"Adding args to front of cache: {JsonConvert.SerializeObject(args)}: {hash}"); AddToFrontOfCache(hash, result); return(true); }
public override CacheEntry Get(object[] args) { string hash = GetHash(args); Debug.WriteLine($"Getting hash: {hash}"); if (!LastIndexCache.ContainsKey(hash)) { return(null); } int lastIndex = LastIndexCache[hash]; var entry = ValueLists[lastIndex]; Debug.WriteLine($"Returning existing entry: {entry.Hash}"); return(entry); }
public override bool Add(object[] args, object result) { string hash = GetHash(args); if (LastIndexCache.ContainsKey(hash)) { return(false); } if (ValueLists.Count >= MaxSize) { RemoveLeastRecentlyUsedEntry(); } Debug.WriteLine($"Adding args to front of cache: {JsonConvert.SerializeObject(args)}: {hash}"); AddToFrontOfCache(hash, result); return(true); }
public bool IsCached(object[] args) { string hash = GetHash(args); return(LastIndexCache.ContainsKey(hash)); }