Microsoft Enterprise Library 5.0: http://www.microsoft.com/download/en/details.aspx? Displaylang = en & id = 15104
Microsoft Enterprise Library 5.0 document address: http://entlib.codeplex.com/releases/view/43135
Cache reference link: http://msdn.microsoft.com/en-us/library/ff664753%28v=PandP.50%29.aspx
1. Install Microsoft Enterprise Library 5.0
2. RunEntlibconfig.exe
3. Add cache Configuration
4. View cache configurations
5. Save as app. config
6. Create a New winformProgram
7. Add Microsoft. Practices. enterpriselibrary. caching reference. The DLL is located at: C: \ Program Files \ Microsoft Enterprise Library 5.0 \ bin.
8. Copy the previously generated app. config to overwrite app. config in the project.
9. DemoCode
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)
{
}
/// <Summary>
/// Set Cache
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Btnsetcache_click ( Object Sender, eventargs E)
{
Cachemanager = (cachemanager) cachefactory. getcachemanager ();
Cachemanager. Add ( " Username " , " Liuyu " );
}
/// <Summary>
/// Get Cache
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Btngetcaching_click ( Object Sender, eventargs E)
{
Cachemanager = (cachemanager) cachefactory. getcachemanager ();
This . Label1.text = cachemanager. getdata ( " Username " ) = Null ? String. Empty: cachemanager. getdata (" Username " ). Tostring ();
}
/// <Summary>
/// Clear Cache
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Btnremovecaching_click ( Object Sender, eventargs E)
{
Cachemanager = (cachemanager) cachefactory. getcachemanager ();
Cachemanager. Remove ( " Username " );
}
}
}