//Add cache named Key1. It will expire in 10 minute
CacheWrapper.Add("Key1", new List<int>(), 10);
//Get the cache
var result = CacheWrapper.Get<List<int>>("Key1");
//Delete the cache
CacheWrapper.Delete("Key1");
public class CacheWrapper
{
private static ObjectCache cache = null;
public static ObjectCache Cache
{
get
{
if (cache == null)
{
cache = MemoryCache.Default;
}
return cache;
}
}
public static void Add(string key, object data, double expireInMinute)
{
Delete(key);
Cache.Add(key, data, DateTime.Now.AddMinutes(expireInMinute));
}
public static object Get(string key)
{
if (!Cache.Contains(key))
return null;
return Cache[key];
}
public static void Delete(string key)
{
if (Cache.Contains(key))
{
Cache.Remove(key);
}
}
}