asp.net Cache缓存的用法


public static void AA()
{

//缓存
var data =GetCache(
() =>
{
//返回缓存的值
return "1111";
},
"key",//缓存的key
3 //缓存时间(分钟)
);

string key = HttpRuntime.Cache["key"] as string;//取值
}

public static T GetCache<T>(Func<T> F, string key, int Minutes)
{
if (HttpRuntime.Cache.Get(key) == null)
{
T local = F();
HttpRuntime.Cache.Insert(key, local, null, System.DateTime.Now.AddMinutes((double)Minutes), Cache.NoSlidingExpiration);
return local;
}
return (T)HttpRuntime.Cache.Get(key);
}

原文地址:https://www.cnblogs.com/zengwangjing/p/8446275.html