微软企业库5.0的下载地址:
微软企业库5.0文档地址:
缓存的参考链接:
1、安装微软企业库5.0
2、运行EntLibConfig.exe
3、增加缓存配置
4、查看缓存配置
5、另存为App.config
6、新建一个winform程序
7、添加Microsoft.Practices.EnterpriseLibrary.Caching 引用,dll的位置是:C:\Program Files\Microsoft Enterprise Library 5.0\Bin
8、把前面生成的App.config拷贝覆盖项目中的App.config
9、demo代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.Practices.EnterpriseLibrary.Caching; namespace CachingDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } ////// 设置缓存 /// /// /// private void btnSetCache_Click(object sender, EventArgs e) { CacheManager cachemanager = (CacheManager)CacheFactory.GetCacheManager(); cachemanager.Add("username", "liuyu"); } ////// 获取缓存 /// /// /// private void btnGetCaching_Click(object sender, EventArgs e) { CacheManager cachemanager = (CacheManager)CacheFactory.GetCacheManager(); this.label1.Text = cachemanager.GetData("username") == null ? String.Empty : cachemanager.GetData("username").ToString(); } ////// 清除缓存 /// /// /// private void btnRemoveCaching_Click(object sender, EventArgs e) { CacheManager cachemanager = (CacheManager)CacheFactory.GetCacheManager(); cachemanager.Remove("username"); } } }