示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        public bool IsCached(object[] args)
        {
            string hash = GetHash(args);

            return(LastIndexCache.ContainsKey(hash));
        }