コード例 #1
0
        public void Can_Check_If_The_Cache_Contains_A_Key()
        {
            Console.WriteLine("Cleaning up before test");
            var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1");

            cache.RemoveAll();
            cache.RemoveAll("sampleCache2");

            Assert.IsFalse(cache.Contains("thisKey", null));

            cache["thisKey"] = "aTestValue";
            Assert.IsTrue(cache.Contains("thisKey", null));
            Assert.IsFalse(cache.Contains("thisKey", "sampleCache2"));

            cache.Add("thisKey", "aTestValue", null, "sampleCache2");
            Assert.IsTrue(cache.Contains("thisKey", "sampleCache2"));

            Console.WriteLine("Cleaning up after test");

            cache.Remove("thisKey", null);
            cache.Remove("thisKey", "sampleCache2");
        }
コード例 #2
0
        public void Can_Add_Cache_Items()
        {
            var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1");
            cache.RemoveAll();
            cache.RemoveAll("sampleCache2");

            var item = new CacheItem("key1", "value1");
            var policy = new CacheItemPolicy();
          
            Assert.IsTrue(cache.Add(item, policy));
            Assert.IsFalse(cache.Add(item, policy));
            Assert.AreEqual(cache.GetCount(null), 1);
            Assert.AreEqual(cache.GetCount("sampleCache1"), 1);

            item.Key = "key2";
            item.Value = "value2";
            item.RegionName = "sampleCache2";

            Assert.IsTrue(cache.Add(item, policy));
            Assert.IsFalse(cache.Add(item, policy));
            Assert.AreEqual(cache.GetCount(null), 1);
            Assert.AreEqual(cache.GetCount("sampleCache2"), 1);
        }
コード例 #3
0
        public void Can_Check_Size_Of_Cache()
        {
            var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1");
            Assert.AreEqual(0, cache.GetCount(null));

            cache["testKey1"] = "aTestValue";
            Assert.AreEqual(1, cache.GetCount(null));
            Assert.AreEqual(1, cache.GetCount("sampleCache1"));
            Assert.AreEqual(0, cache.GetCount("sampleCache2"));
            cache["testKey2"] = "anotherTestValue";
            Assert.AreEqual(2, cache.GetCount(null));

            cache.Add("testKey1", "testValue", null, "sampleCache2");
            Assert.AreEqual(1, cache.GetCount("sampleCache2"));
        }
コード例 #4
0
        public void Can_Result_Multiple_Keys_Including_Non_Extant()
        {
            var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1");
            cache.RemoveAll();

            cache["key1"] = "apple";
            cache["key2"] = "pear";
            cache["key3"] = "orange";

            var keys = new string[] {"key1", "key2", "key3", "key4"};
            var results = cache.GetValues(keys, null);
  
            Assert.AreEqual(results.Count, 3);
            Assert.AreEqual(results["key1"], "apple");
            Assert.AreEqual(results["key2"], "pear");
            Assert.AreEqual(results["key3"], "orange");

            cache.Add("key1", "apple", null, "sampleCache2");
            cache.Add("key2", "pear", null, "sampleCache2");
            cache.Add("key3", "orange", null, "sampleCache2");

            results = cache.GetValues("sampleCache2", "key1", "key2", "key3", "key4");

            Assert.AreEqual(results.Count, 3);
            Assert.AreEqual(results["key1"], "apple");
            Assert.AreEqual(results["key2"], "pear");
            Assert.AreEqual(results["key3"], "orange");
        }