public ActionResult SetCacheAbsolute()
        {
            var currentId = i++;

            sqlCache.Set($"key{currentId}", new Foo {
                Bar = $"quito{currentId}"
            }, DateTimeOffset.Now.AddMinutes(5));

            return(RedirectToHome());
        }
Beispiel #2
0
        public void GetCount()
        {
            // ARRANGE
            SqlCache cache = new SqlCache(connectionString);

            cache.Add("1", "GetCountValue1", DateTime.Now.AddMinutes(30));
            cache.Set("2", "GetCountValue2", new System.Runtime.Caching.CacheItemPolicy {
                AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1)
            });

            cache.Set("3", "GetCountValue3", new System.Runtime.Caching.CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            });
            // ACT
            var count = cache.GetCount();

            // ASSERT
            Assert.AreEqual(3, count);
        }
Beispiel #3
0
        public void GetEnumerable()
        {
            // ARRANGE
            var      values = new string[] { "GetEnumerableValue1", "GetEnumerableValue2", "GetEnumerableValue3" };
            SqlCache cache  = new SqlCache(connectionString);

            cache.Add("1", values[0], DateTime.Now.AddMinutes(30));
            cache.Set("2", values[0], new System.Runtime.Caching.CacheItemPolicy {
                AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1)
            });

            cache.Set("3", values[0], new System.Runtime.Caching.CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            });
            // ACT
            foreach (var item in cache)
            {
                // ASSERT
                Assert.IsTrue(values.Any(x => x == item.Value.ToString()));
            }
        }