📄 webcache.cs
字号:
using System;
using System.Web;
using System.Web.Caching;
namespace Club.Framework.Util
{
/// <summary>
/// Allows caching in application in applications hosted inside and out of IIS
/// </summary>
public class WebCache
{
private WebCache(){}
public static Cache Cache(HttpContext context)
{
return GetCache(context);
}
public static Cache Cache()
{
return Cache(HttpContext.Current);
}
public static void AssemblyCacheDependency(string cacheKey, object obj)
{
AssemblyCacheDependency(cacheKey,obj,HttpContext.Current);
}
public static void AssemblyCacheDependency(string cacheKey, object obj, HttpContext context)
{
if(cacheKey != null && obj != null)
{
CacheDependency cacheDependency = new CacheDependency(obj.GetType().Assembly.Location);
WebCache.Cache().Insert(cacheKey,obj,cacheDependency);
}
}
private static Cache GetCache(HttpContext context)
{
if(context != null)
{
return context.Cache;
}
else
{
return HttpRuntime.Cache;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -