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);
}

posted @ 2018-02-13 11:11  会飞的小鲸鱼  阅读(132)  评论(0编辑  收藏  举报