添加缓存
public static void Set(string cacheKey, object cacheValue, int timeout)
{
if (string.IsNullOrEmpty(cacheKey))
{
return;
}
if (null == cacheValue)
{
Remove(cacheKey);
return;
}
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);
if (timeout <= 0)
{
cache.Insert(cacheKey, cacheValue, null, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.High, callBack);
}
else
{
cache.Insert(cacheKey, cacheValue, null, DateTime.Now.AddSeconds(timeout), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, callBack);
}
}
获取缓存
public static object Get(string cacheKey)
{
if (string.IsNullOrEmpty(cacheKey))
{
return null;
}
return cache.Get(cacheKey);
}
删除缓存
public static void Remove(string cacheKey)
{
if (!string.IsNullOrEmpty(cacheKey))
cache.Remove(cacheKey);
}