Esempio n. 1
0
        public void TestNonexistingKeyInvalidate()
        {
            var cache = new MemCache <string, int>();

            Assert.IsFalse(cache.Invalidate("notexists"));

            cache.GetOrCreate("key", () => 0, TimeSpan.FromSeconds(1));
            Assert.IsTrue(cache.Invalidate("key"));
            Assert.IsFalse(cache.Invalidate("key"));
        }
Esempio n. 2
0
        public void Start()
        {
            var cache = new MemCache <int, CacheMe>();

            Console.WriteLine("Getting non-cached object two times");
            cache.GetOrCreate(0, () => new CacheMe(0), TimeSpan.Zero);
            cache.GetOrCreate(0, () => new CacheMe(0), TimeSpan.Zero);
            Console.WriteLine("Creating cached object");
            cache.GetOrCreate(1, () => new CacheMe(1), TimeSpan.FromMilliseconds(100));
            Console.WriteLine("Getting cached object two times");
            cache.GetOrCreate(1, () => new CacheMe(1), TimeSpan.FromMilliseconds(100));
            cache.GetOrCreate(1, () => new CacheMe(1), TimeSpan.FromMilliseconds(100));
            Console.WriteLine("Wait cache to expire");
            Thread.Sleep(100);
            cache.GetOrCreate(1, () => new CacheMe(1), TimeSpan.FromMilliseconds(100));
        }