12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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;
- }
- }
- }
- }
|