An item in the cache
Esempio n. 1
0
        public void UpdateValueTest()
        {
            CacheItem cacheItem = new CacheItem("key", 3);

            Assert.AreEqual(3, (int)cacheItem.Value, "value");

            cacheItem.Value = "hello";
            Assert.AreEqual("hello", (string)cacheItem.Value, "value");
        }
Esempio n. 2
0
        public void CreateTest()
        {
            CacheItem cacheItem = new CacheItem("key", 3);

            Assert.AreEqual("key", cacheItem.Key, "Key");
            Assert.AreEqual(3, (int)cacheItem.Value, "value");
            Assert.IsTrue(cacheItem.LastAccessed <= DateTime.Now, "Now");
            Assert.IsTrue(cacheItem.LastAccessed > DateTime.Today, "Today");
        }
Esempio n. 3
0
        public void UpdateLastAccessedTest()
        {
            CacheItem cacheItem = new CacheItem("key", 3);

            DateTime cacheItemCreated = cacheItem.LastAccessed;

            Thread.Sleep(100);
            cacheItem.UpdateLastAccessed();
            Assert.IsTrue(cacheItem.LastAccessed > cacheItemCreated);
        }
Esempio n. 4
0
 /// <summary>
 /// Write a value to the cache
 /// </summary>
 /// <param name="key">the cache key</param>
 /// <param name="data">the value cached</param>
 public void Write(string key, object data)
 {
     if (this.cacheData.ContainsKey(key))
     {
         this.cacheData[key].Value = data;
     }
     else
     {
         CacheItem newCacheItem = new CacheItem(key, data);
         this.cacheData.Add(key, newCacheItem);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Return true if the item has expired, is past the timeout
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private bool ItemHasTimedOut(CacheItem item)
 {
     return item.LastAccessed < DateTime.Now - this.Timeout;
 }