public void ClearCacheTest() { // set up cache with an initial value var cache = new InstanceByKeyCache <string, string>(); var key = "randomKey"; var cachedValue = "Initial value"; // get value from cache and check it matches initial var value = cache.Get(key, (localKey) => { return(cachedValue); }, CacheDuration); Assert.AreEqual("Initial value", value); // clear the cache cache.Clear(); // change the cached value cachedValue = "Changed value"; // check that it returns the changed value value = cache.Get(key, (localKey) => { return(cachedValue); }, CacheDuration); Assert.AreEqual("Changed value", value); }
public void CacheByArrayKeyTest() { var cache = new InstanceByKeyCache <string, ArrayKey <int> >(); var key1 = new ArrayKey <int>(new[] { 1, 2, 3 }); var key2 = new ArrayKey <int>(new[] { 1, 2, 3 }); var value = cache.Get(key1, (localKey) => { return("First"); }, CacheDuration); value = cache.Get(key2, (localKey) => { return("Second"); }, CacheDuration); Assert.AreEqual("First", value); }
public void GetValueTest() { var cache = new InstanceByKeyCache <string, string>(); var key = "hi"; var value = cache.Get(key, (localKey) => { return("Hello"); }, CacheDuration); Assert.AreEqual("Hello", value); }