. NET distributed Cache (Memcached) implementation

Source: Internet
Author: User

Prepare a query for a very trivial data cache, combined with a variety of considerations, consider using memcached

What is memcached?

Memcached is a high-performance, distributed memory object cache that can be used in dynamic applications to reduce database load and improve access speed.

What can mencached cache?

By maintaining a unified, huge hash table in memory, memcached can cache data in a variety of formats. Such as: images, video, text, and the results of database retrieval.

1, server-side installation method:

installing memcached for Win64

a lot of addresses on the network, after downloading, in the CMD run the installation program in the folder

Memcached.exe -D intall // Installation
Memcached.exe -D start //boot start

2. Client:

Download file: https://sourceforge.net/projects/memcacheddotnet/

3. Application:

A simple test:

First encapsulate a simple tool class

namespacejikecomponent{/// <summary>    ///Distributed cache simple use class///by Wzx at 2015-05-12/// </summary>     Public classMemcachedhelper {Private Const stringPoolname ="Jkcache"; Private StaticMemcachedclient MC; Private StaticMemcachedhelper _instance =NULL;  Public Staticmemcachedhelper Instance {Get            {                if(_instance = =NULL) {_instance=NewMemcachedhelper (); }                return_instance; }        }        PrivateMemcachedhelper () {string[] ServerList = {"127.0.0.1:11211" }; Sockiopool Pool=sockiopool.getinstance (poolname); Pool.            Setservers (serverlist); Pool. Initconnections=3;//number of initial connectionsPool. Minconnections =3;//minimum number of connectionsPool. MaxConnections =5;//Maximum number of connectionsPool. Socketconnecttimeout = +;//set the socket timeout for a connectionPool. Sockettimeout = the;//Set socket timeout readPool. Maintenancesleep = -;//Sets the sleep time that the maintenance thread runs. If set to 0, the maintenance thread will not start, and 30 is waking up every 30 seconds//Gets or sets the fault flag for the pool. //If this flag is set to true then the socket connection fails and an attempt is made to return a socket from another server if it exists. //if set to false, a socket is obtained if one exists.  Otherwise, NULL is returned if it cannot connect to the requested server. Pool. Failover =true; Pool. Nagle=false;//If False, the Nagle algorithm is closed for all created socketspool.            Initialize (); MC=Newmemcachedclient (); Mc. Poolname=poolname; Mc. EnableCompression=false; }              /// <summary>       ///adding a piece of data to the memcached cache/// </summary>       /// <param name= "key" >Key</param>       /// <param name= "value" >value</param>       /// <param name= "expiry" >Expiry Time</param>       /// <returns>returns whether the add succeeded</returns>        Public BOOLSetValue (stringKeyObjectvalue, DateTime expiry) {           returnMC.       Set (key, value, expiry); }       /// <summary>       ///using key to get an object/// </summary>       /// <param name= "key" >Key</param>       /// <returns>Object</returns>        Public ObjectGetValue (stringkey) {                     returnMC.       Get (key); }        /// <summary>        ///removing objects from the cache/// </summary>       /// <param name= "key" >Key</param>       /// <returns>returns whether the removal succeeded</returns>        Public BOOLDelvalue (stringkey) {           returnMC.       Delete (key); }    }}

b/S test results:

C/S Continue testing:

The client-side code is simply not working, it is not posted.

The simple test is done.

. NET distributed Cache (Memcached) implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.