Beispiel #1
0
        public void Add(TKey key, TValue val)
        {
            if (cache.Count >= capacity)
            {
                RemoveFirst();
            }

            var cacheItem = new LruCacheItem <TKey, TValue>(key, val);
            var node      = new LinkedListNode <LruCacheItem <TKey, TValue> >(cacheItem);

            lastUsedItems.AddLast(node);
            cache.Add(key, node);
        }
Beispiel #2
0
        private bool IsItemTooOld(LruCacheItem <TKey, TValue> cacheItem)
        {
            var now = DateTime.Now;

            return(now - cacheItem.AddingTime > maxLifeTime);
        }