Ejemplo n.º 1
0
        public void Test1()
        {
            var cacheLinkedList = new CacheLinkedList <string, string>();

            cacheLinkedList.Add(new CacheNode <string, string>("item1", "1"));
            cacheLinkedList.Add(new CacheNode <string, string>("item2", "2"));
            var removed = cacheLinkedList.Remove();

            Assert.AreEqual("item1", removed.GetKey());
            Assert.AreEqual("1", removed.GetData());
            removed = cacheLinkedList.Remove();
            Assert.AreEqual("item2", removed.GetKey());
            Assert.AreEqual("2", removed.GetData());
        }
Ejemplo n.º 2
0
        public void Test2()
        {
            var cacheLinkedList = new CacheLinkedList <string, string>();

            for (var i = 0; i < 1000; i++)
            {
                cacheLinkedList.Add(new CacheNode <string, string>(i + "", i + ""));
            }

            for (var i = 0; i < 1000; i++)
            {
                var removed = cacheLinkedList.Remove();
                Assert.AreEqual(i + "", removed.GetKey());
                Assert.AreEqual(i + "", removed.GetData());
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs a new instance of the cache.
 /// </summary>
 /// <param name="cacheSize">
 /// The number of items to store in the cache
 /// </param>
 /// <param name="concurrency">
 /// The expected number of concurrent requests to the cache
 /// </param>
 internal LruCache(int cacheSize, int concurrency)
 {
     if (concurrency <= 0)
     {
         throw new ArgumentOutOfRangeException(
                   "concurrency",
                   "Concurrency must be a positive integer greater than 0.");
     }
     CacheSize   = cacheSize;
     _dictionary = new ConcurrentDictionary <K, CachedItem>(
         concurrency, cacheSize);
     _linkedLists = new CacheLinkedList[concurrency];
     for (int i = 0; i < _linkedLists.Length; i++)
     {
         _linkedLists[i] = new CacheLinkedList(this);
     }
 }
Ejemplo n.º 4
0
 internal CachedItem(CacheLinkedList list, K key, V value)
 {
     List  = list;
     Key   = key;
     Value = value;
 }