Everyone is familiar with memcached. The introduction from Baidu encyclopedia is as follows:
Memcached is a high-performance distributed memory object Cache System for dynamic web applications to reduce database load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in C, but the client can write it in any language and communicate with the daemon through memcached protocol.
After studying it today, it is a simple test. Next we will introduce our steps. If there is anything that is not in place or wrong, please correct me. Thank you!
1. First download the latest source code from the memcached website at http://memcached.org/. the latest version is: memcached 1.4.15.
2. Use C ++ or TC to compile the source code and then generate the EXE file. I have compiled files here, but the version is 1.2.5. Click here to download them.
3. decompress the file to c: \ memcached.
4. Enter 'C: \ memcached \ memcached.exe-D install' in the command line'
5. Enter 'C: \ memcached \ memcached.exe-D start' in the command line to start memcached. The default listening port is port 11211. You can view the help information through memcached.exe-H.
6. Download memcached. Net client Lib
7. decompress the package and you will see the source code. Use vs to open the package. After compilation, copy the following DLL file in the release folder.
8. Create a new test project, such as a web application. Add references to the above 4 DLL files.
9. Write the test code in index. aspx and index. aspx. cs. For example, my example is:
View code
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "index. aspx. cs" inherits = "dearbruce. memcachedtest. webapp. Index" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> View code
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. ui; using system. web. UI. webcontrols; using memcached. clientlibrary; namespace dearbruce. memcachedtest. webapp {public partial class index: system. web. UI. page {private const string memcachedkey = "testkey"; protected void page_load (Object sender, eventargs e) {If (! Ispostback) {}} protected void initsockiopool () {string [] serverlist = {"127.0.0.1: 11211"}; // initialize the pool sockiopool = sockiopool. getinstance (); pool. setservers (serverlist); pool. initconnections = 3; pool. minconnections = 3; pool. maxconnections = 5; pool. socketconnecttimeout = 1000; pool. sockettimeout = 3000; pool. maintenancesleep = 30; pool. failover = true; pool. nagle = false; pool. initialize () ;} Protected void btnsetvaluetomemcached_click (Object sender, eventargs e) {string txtuserinput = this.txt userinput. text; If (string. isnullorempty (txtuserinput) {showmessage ("Enter the value to be set! "); Return;} // obtain the client instance memcachedclient MC = new memcachedclient (); Mc. enablecompression = false; Mc. Set (memcachedkey, txtuserinput); showmessage (" set successfully! ");} Protected void btngetvaluefrommemcached_click (Object sender, eventargs e) {memcachedclient MC = new memcachedclient (); If (MC. keyexists (memcachedkey) {showmessage ("your input value is:" + MC. get (memcachedkey ). tostring ();} else {showmessage (string. format ("memcached does not contain a key \" {0! ", Memcachedkey) ;}} protected void btndeletevaluefrommemcached_click (Object sender, eventargs e) {memcachedclient MC = new memcachedclient (); MC. delete (memcachedkey); // remove the project where the key in the cache is test} protected void handle (Object sender, eventargs e) {initsockiopool ();} protected void btnclosepool_click (Object sender, eventargs e) {sockiopool. getinstance (). shutdown (); // close the pool and disable sockets} protected void showmessage (string message) {This. ltmessage. text + = message ;}}}
10. Run, test, success!
Refer to the URL:
Memcached strike-blog comment timeout problem handling process
Memcached-Google Code
Discuz! Integrate memcached distributed cache in NT-daizj-Dai zhenjun-blog Park
Thank you!