Ejemplo n.º 1
0
 public void Put(object key, object value)
 {
     lock (_syncRoot)
     {
         cache.Add(key, value);
     }
 }
Ejemplo n.º 2
0
		public void PutAndRemove()
		{
			int size = 10;
			IDictionary cache = new LRUMap(size);

			cache.Add("key:" + 1, "data:" + 1);
			cache.Remove("key:" + 1);
			Assert.IsNull(cache["key:" + 1]);
		}
Ejemplo n.º 3
0
		public void AddDoesBoundsChecking()
		{
			var map = new LRUMap(128);

			for (int i = 0; i < 200; i++)
				map.Add("str" + i, i);

			Assert.That(map.Count, Is.EqualTo(128));
		}
 public object this[object key]
 {
     get
     {
         lock (_syncRoot)
         {
             object result = softReferenceCache[key];
             if (result != null)
             {
                 strongReferenceCache.Add(key, result);
             }
             return(result);
         }
     }
 }
Ejemplo n.º 5
0
		public void PutWithNoSizeLimit()
		{
			int size = 10;
			IDictionary cache = new LRUMap();

			for (int i = 0; i < size; i++)
			{
				cache.Add("key:" + i, "data:" + i);
			}

			for (int i = 0; i < size; i++)
			{
				string data = (string)cache["key:" + i];
				Assert.AreEqual("data:" + i, data, "Data is wrong.");
			}
		}
Ejemplo n.º 6
0
 public object this[object key]
 {
     [MethodImpl(MethodImplOptions.Synchronized)]
     get
     {
         lock (SyncRoot)
         {
             object result = softReferenceCache[key];
             if (result != null)
             {
                 strongReferenceCache.Add(key, result);
             }
             return(result);
         }
     }
 }
Ejemplo n.º 7
0
		public void GetEntrySet()
		{
			int size = 10;
			IDictionary cache = new LRUMap(size);

			for (int i = 0; i < size; i++)
			{
				cache.Add("key:" + i, "data:" + i);
			}
			Assert.AreEqual(size, cache.Keys.Count, "Set contains the wrong number of items.");

			// check minimal correctness
			foreach (DictionaryEntry entry in cache)
			{
				Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:"));
			}
		}
Ejemplo n.º 8
0
		public void PutWithSizeLimitOfZero()
		{
			IDictionary cache = new LRUMap(0);

			cache.Add("key", "data");

			string data = (string)cache["key"];
			Assert.IsNull(data, "Data is wrong.");
		}