web项目服务器缓存怎么做,对Cache类简单的封装,实现web项目服务器端缓存。

Cache介绍:

出生于.NetFramework 2,实现用于 Web 应用程序的缓存。

代码

简单的封装,有更好的封装代码,欢迎指点。

''''

///

/// 缓存操作类

///

public class DataCache

{

///

/// 获取当前应用程序指定CacheKey的Cache值

///

///

///

public static object GetCache(string CacheKey)

{

System.Web.Caching.Cache objCache = HttpRuntime.Cache;

return objCache[CacheKey];

}

///

/// 设置当前应用程序指定CacheKey的Cache值

///

///

///

/// 超过多少秒后过期

public static void SetCache(string CacheKey, object objObject, long Seconds)

{

System.Web.Caching.Cache objCache = HttpRuntime.Cache;

objCache.Insert(CacheKey, objObject, null, System.DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero);

}

///

/// 移除指定key的数据缓存

///

/// cache 的key值

public static void RemoveCache(string CacheKey)

{

System.Web.Caching.Cache objCache = HttpRuntime.Cache;

objCache.Remove(CacheKey);

}

}

'''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值