public static class CacheManager
public static void ClearCacheOf<T>(string key)
if (!string.IsNullOrEmpty(key) && HttpContext.Current != null)
HttpContext.Current.Cache.Remove(typeof(T) + key);
public static T CacheVerification<T>(int timeToLive, string identifier, Func<T> function)
if (HttpContext.Current == null)
string key = typeof(T) + identifier;
var requestedCachedItem = GetFromCache<T>(key);
if (requestedCachedItem != null)
response = requestedCachedItem;
AddToCache(key, response, timeToLive);
private static void AddToCache<T>(string key, T objectToAdd, int ttl)
HttpContext.Current.Cache.Insert(key, objectToAdd, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(ttl));
private static T GetFromCache<T>(string key)
return (T)HttpContext.Current.Cache[key];