Enterprise Library 之缓存

Enterprise Library 中的缓存管理是很方便的.看下面的例子就可以知道.

首先创建一个web站点,添加一个web.config文件,使用Enterprise Library打开config文件,
添加一个缓存模块,如图:

在项目中添加引用,如图:

然后在后台我输入一下代码:

using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  System.Data.Common;
using  System.Data.SqlClient;
using  Microsoft.Practices.EnterpriseLibrary.Caching;
using  Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

public   partial   class  _Default : System.Web.UI.Page 
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
int id = 0;
        
string name = "winnerzone";

        
//创建一个缓存管理器
        CacheManager testcaching = CacheFactory.GetCacheManager("Cache Manager");

        
//添加要进行缓存的数据,缓存时间为10分钟,添加key为0
        testcaching.Add(id.ToString(), name, CacheItemPriority.Normal, nullnew

SlidingTime(TimeSpan.FromMinutes(
10)));

        
//取出缓存中key为0的数据
        string rname = (string)testcaching.GetData(id.ToString());
        Response.Write(rname);

        
//从缓存中移出key=0的项
        testcaching.Remove("0");
        rname 
= (string)testcaching.GetData(id.ToString());
        Response.Write(rname
+"<br>已经被清除掉了!");
        
//清除缓存
        testcaching.Flush();
    }

}
好了运行程序看看?是不是很方便?
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值