entlib5.0 学习笔记 caching application block 简单使用示例
1.使用示例
2.参考资料及源代码下载
1.简单使用示例
该简单示例不包含比较详细的配置信息(将在下面的笔记中),仅仅是对caching application block如何使用的入门级介绍。
1.1 在vs2008中新建一个控制台应用程序,并向其中添加一个应用程序配置文件
1.2 点击Edit Enterprise Library v5 Configuration,打开gui配置器
1.3 在entlib的gui配置器中选择blocks菜单选项,点击add caching settings,保持默认配置,保存该配置文件。
1.4 添加entlib引用
1.5 编写测试代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Caching; using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations; namespace CacheApplicationBlockTest { class Program { static void Main(string[] args) { ICacheManager cacheManager = (CacheManager)CacheFactory.GetCacheManager(); int cachedInteger = 123; cacheManager.Add("cachedInteger", cachedInteger); Console.WriteLine("Cached the integer,the integer value is {0}", cachedInteger); int retrivedInteger = (int)cacheManager.GetData("cachedInteger"); Console.WriteLine("Get the cached integer {0}", retrivedInteger); Console.ReadLine(); } } }