using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Caching; namespace EnVisage.Code.Cache { public class CacheManager { private static CacheManager instance; public static CacheManager Instance { get { return instance ?? new CacheManager(); } } protected CacheManager() { } private System.Web.Caching.Cache cache = HttpContext.Current.Cache; public void AddToCache(string key, object value) { if(!IsInCache(key)) cache.Add(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(60), CacheItemPriority.Default, null); else cache.Insert(key, value); } public void RemoveFromCache(string key) { if (cache[key] != null) cache.Remove(key); } public bool IsInCache(string key) { if (cache.Count == 0) return false; else return cache[key] != null; } public object GetCacheData(string key) { if (IsInCache(key)) return cache[key]; else return null; } } }