Exemple #1
0
        public void Can_clear_cache()
        {
            using (var cache = new MemoryCache(new MemoryCacheOptions()))
            {
                var obj1 = new object();
                var obj2 = new object();
                var obj3 = new object();

                var cacheManager = new MemoryCacheManager(cache, new CacheOptions());
                cacheManager.Set("obj1", obj1);
                cacheManager.Set("obj2", obj2);
                cacheManager.Set("obj3", obj3);

                Assert.NotEmpty(cacheManager.Keys);

                cacheManager.Clear();

                // A little hacky, there must be a better way
                // to clear cache and await post eviction
                Thread.Sleep(1000);

                Assert.Empty(cacheManager.Keys);
            }
        }
Exemple #2
0
        public void Can_remove_entry()
        {
            using (var cache = new MemoryCache(new MemoryCacheOptions()))
            {
                var obj = new object();

                var cacheManager = new MemoryCacheManager(cache, new CacheOptions());
                cacheManager.Set("obj", obj);

                Assert.Contains(cacheManager.Keys, key => key == "obj");

                cacheManager.Remove("obj");

                Assert.DoesNotContain(cacheManager.Keys, key => key == "obj");
            }
        }
Exemple #3
0
        public void Can_set_entry()
        {
            using (var cache = new MemoryCache(new MemoryCacheOptions()))
            {
                var obj = new object();

                var cacheManager = new MemoryCacheManager(cache, new CacheOptions());
                cacheManager.Set("obj", obj);

                Assert.Contains(cacheManager.Keys, key => key == "obj");

                var fromCache = cache.Get("obj");

                Assert.Equal(obj, fromCache);
            }
        }