using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Caching; using Bowin.Common.JSON; namespace Bowin.Common.Cache { public class HttpCacheProvider : ICacheProvider { private static System.Web.Caching.Cache cache { get { return System.Web.HttpContext.Current.Cache; } } static HttpCacheProvider() { } public object Add(string key, object entry, DateTime utcExpiry) { var result = Get(key); if (result == null) { cache.Insert(key, entry, null, System.Web.Caching.Cache.NoAbsoluteExpiration, utcExpiry.Subtract(DateTime.Now), CacheItemPriority.High, delegate { }); result = entry; } return result; } public object Get(string key) { return cache[key]; } public void Remove(string key) { cache.Remove(key); } public void Set(string key, object entry, DateTime utcExpiry) { var result = Get(key); if (result == null) { cache.Insert(key, entry, null, System.Web.Caching.Cache.NoAbsoluteExpiration, utcExpiry.Subtract(DateTime.Now), CacheItemPriority.High, delegate { }); result = entry; } else { cache[key] = entry; } } } }