Exemple #1
0
        private static void AddToCache(HttpContext context, string path, string output)
        {
            OutputCacheProvider defaultOutputCacheProvider = OutputCache.Providers[OutputCache.DefaultProviderName];

            if (defaultOutputCacheProvider != null)
            {
                defaultOutputCacheProvider.Add(path, output, DateTime.Now.AddSeconds(DefaultExpiry));
            }
            else
            {
                context.Cache.Add(path, output, null, DateTime.Now.AddSeconds(DefaultExpiry), Cache.NoSlidingExpiration,
                                  CacheItemPriority.Low, null);
            }
        }
        private void AddToCache(HttpContext context, string path, string output)
        {
            OutputCacheProvider oc =
                OutputCache.Providers[OutputCache.DefaultProviderName];

            if (oc != null)
            {
                oc.Add(path, output, DateTime.Now.AddSeconds(60));
            }
            else
            {
                context.Cache.Add(path, output, null, DateTime.Now.AddSeconds(60),
                                  Cache.NoSlidingExpiration, CacheItemPriority.Low, null);
            }
        }
 public void Add_One_Valid()
 {
     _outputCache.Add("a", "b", _outputCache.Cache.Clock.GetCurrentInstant().Plus(Duration.FromMinutes(10)).ToDateTimeOffset(), null);
     Assert.AreEqual("b", _outputCache.Get("a"));
     Assert.AreEqual("b", _outputCache.Get <string>("a"));
 }
 /// <summary>
 /// Add sthe given <see cref="cacheItem" /> in the cache.
 /// </summary>
 /// <param name="key">The cache key to add.</param>
 /// <param name="cacheItem">The cache item to add.</param>
 /// <param name="utcExpiry">The cache item UTC expiry date and time.</param>
 public void AddItem(string key, CacheItem cacheItem, DateTime utcExpiry)
 {
     _outputCacheProvider.Add(key, cacheItem, utcExpiry);
 }