General Memcached class (based on enyim.com Memcached Client)

Source: Internet
Author: User
Tags delete cache

1. If you use the official method, you have configured parameters and Server IP addresses in web. config. For example:

<?xml version=?><configuration>  <configSections>        <sectionGroup name=>      <section name= type=/>    </sectionGroup>    <section name= type= />   </configSections> <enyim.com>     <memcached protocol=>      <servers>         <add address= port= />        <add address= port= />        <add address= port= />        <add address= port= />      </servers>      <socketPool minPoolSize= maxPoolSize= connectionTimeout= deadTimeout= />    </memcached>  </enyim.com>   <system.web>    <compilation debug= targetFramework=/>  </system.web></configuration>

You can use this generic class to automatically call the configuration in web. config.

Add cache AddCache (key, (MemcachedClient mc = add cache AddCache (key, value, (MemcachedClient mc = get the cache GetCache (MemcachedClient mc = whether the cache IsExists (MemcachedClient mc = mc. get (key )! = Delete cache (false if the key does not exist) DelCache (MemcachedClient mc = clear cache (MemcachedClient mc =View Code 2. If you do not want to configure web. config, use the following generic class. Create Memcache client MemcachedClient CreateServer (List <IPEndPoint> = MemcachedClientConfiguration (); (I =; I <serverList. count; I ++ System. net. IPEndPoint (IPAddress. parse (serverList [I]. address. toString (), serverList [I]. port); = (PlainTextAuthenticator); config. authentication. parameters [] =; config. authentication. parameters [] =; MemcachedClient mac = MemcachedClient (config); add cache AddCache (List <IPEndP Oint> serverList, key, (MemcachedClient mc = add cache AddCache (List <IPEndPoint> serverList, key, value, (MemcachedClient mc = get cache GetCache (List <IPEndPoint> serverList, (MemcachedClient mc = whether the cache IsExists (List <IPEndPoint> serverList, (MemcachedClient mc = mc. get (key )! = Delete cache (if the key does not exist, false is returned) DelCache (List <IPEndPoint> serverList, (MemcachedClient mc = clear cache FlushCache (List <IPEndPoint> (MemcachedClient mc =View Code

 

Related Article

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.