One: Installation of memcached
Step1. Download the Windows stable version of Memcache(http://jehiah.cz/projects/memcached-win32) (Here I have downloaded memcached 1.2.1 for Win32 binaries (DEC, 2006) this version), unzip and put under a disk, such as in the c:\memcached
Step2. Enter the ' c:\memcached\memcached.exe-d install ' installation at the terminal (also known as the cmd Command interface)
Step3. Re-enter: ' c:\memcached\memcached.exe-d start ' starts.
PS: memcached will start automatically every time a service is turned on for Windows. This way the server side is already installed.
Two: . NET memcached Client Library
Download file:https://sourceforge.net/projects/memcacheddotnet/
Put the Commons.dll,icsharpcode.sharpziplib.dll,log4net.dll,memcached.clientlibrary.dll in the bin directory
Reference Memcached.ClientLibrary.dll
Program examples
CodeusingSystem;
usingSystem.Collections;
usingMemcached.clientlibrary;
usingSystem.Text;
namespaceMemcache
{
Public Partial class_default:system.web.ui.page
{
protected voidPage_Load (Objectsender, EventArgs e)
{
if (!IsPostBack)
{
if(request["Action"] == "Clear")
This. Clear ();
Else
This. Test ();
}
}
Public voidClear ()
{
string[] Servers= { "192.168.1.113:11211", "192.168.202.128:11211" };
//Initialize Pool
Sockiopool Pool=sockiopool.getinstance ();
Pool. Setservers (servers);
Pool. Initconnections= 3;
Pool. Minconnections= 3;
Pool. MaxConnections= 5;
Pool. Socketconnecttimeout= +;
Pool. Sockettimeout= the;
Pool. Maintenancesleep= -;
Pool. Failover= true;
Pool. Nagle= false;
Pool. Initialize ();
Memcachedclient MC= NewMemcached.ClientLibrary.MemcachedClient ();
Mc. EnableCompression= false;
Mc. Delete ("Cache");
Mc. Delete ("Endcache");
Response.Write ("Empty Cache succeeded");
}
Public voidTest ()
{
//Distributing MEMCACHEDF Service IP ports
string[] Servers= { "192.168.1.113:11211", "192.168.202.128:11211" };
//Initialize Pool
Sockiopool Pool=Sockiopool.getinstance ();
Pool. Setservers (servers);
Pool. Initconnections= 3;
Pool. Minconnections= 3;
Pool. MaxConnections= 5;
Pool. Socketconnecttimeout= +;
Pool. Sockettimeout= the;
Pool. Maintenancesleep= -;
Pool. Failover= true;
Pool. Nagle= false;
Pool. Initialize ();
//Client Instance
memcachedclient MC= NewMemcached.ClientLibrary.MemcachedClient ();
Mc. EnableCompression= false;
StringBuilder SB= NewStringBuilder ();
//Write Cache
sb. Appendline ("Write Cache test:");
Sb. Appendline ("<br>_______________________________________<br>");
if(MC. Keyexists ("Cache"))
{
Sb. Appendline ("cached cache already exists");
}
Else
{
Mc. Set ("Cache", "Write Cache time:" +DateTime.Now.ToString ());
Sb. Appendline ("the cache was successfully written to the cache");
}
Sb. Appendline ("<br>_______________________________________<br>");
Sb. Appendline ("read the cache content as follows:<br>");
Sb. Appendline (MC. Get ("Cache"). ToString ());
//Test Cache Expiration
sb. Appendline ("<br>_______________________________________<br>");
if(MC. Keyexists ("Endcache"))
{
Sb. Appendline ("the cache Endcache already exists and the expiration time is:" +MC. Get ("Endcache"). ToString ());
}
Else
{
Mc. Set ("Endcache", DateTime.Now.AddMinutes (1). ToString (), DateTime.Now.AddMinutes (1));
Sb. Appendline ("Cache has been updated to write to Endcache, write time:" +DateTime.Now.ToString ()+"Expiry time:" +DateTime.Now.AddMinutes (1). ToString ());
}
//Analyze Cache Status
Hashtable HT=MC. Stats ();
Sb. Appendline ("<br>_______________________________________<br>");
Sb. Appendline ("Memcached Stats:");
Sb. Appendline ("<br>_______________________________________<br>");
foreach(DictionaryEntry deinchHT)
{
Hashtable Info=(Hashtable) de. Value;
foreach(DictionaryEntry de2inchInfo
{
Sb. Appendline (De2. Key.tostring ()+ ": " +De2. Value.tostring ()+ "<br>");
}
}
Response.Write (sb.) ToString ());
}
}
}
Transferred from: http://www.cnblogs.com/Caceolod/articles/1710342.html