Simple-spring-memcached Cache Setup

Source: Internet
Author: User

The cache used in the project is often known to use and has not been tried to build it. Just this time my own graduation can be used to build the cache. The others don't say much, just look at the operation. The first is to rely on Simple-spring-memcached's rack package in pom.xml .

1        <Dependency>2             <groupId>Com.google.code.simple-spring-memcached</groupId>3             <Artifactid>Xmemcached-provider</Artifactid>4             <version>3.3.0</version>5         </Dependency>

Add a Applicationcontext-ssm.xml file to the project that contains:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3 XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:context= "Http://www.springframework.org/schema/context"4 Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:util= "Http://www.springframework.org/schema/util"5 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 6 HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd7 Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd8 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd9 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd ">Ten  One     <ImportResource= "Classpath:simplesm-context.xml" /> A     <Aop:aspectj-autoproxy/> -     <Context:annotation-config/> -      the     <Beanname= "Defaultmemcachedclient"class= "Com.google.code.ssm.CacheFactory"> -         < Propertyname= "Cacheclientfactory"> -             <Beanclass= "Com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" /> -         </ Property> +         < Propertyname= "Addressprovider"> -             <Beanclass= "Com.google.code.ssm.config.DefaultAddressProvider"> +                   < Propertyname= "Address"value= "127.0.0.1:11211" /> A             </Bean> at         </ Property> -         < Propertyname= "Configuration"> -             <Beanclass= "Com.google.code.ssm.providers.xmemcached.XMemcachedConfiguration"> -                 < Propertyname= "Consistenthashing"><!--The consistenthashing property defines the lookup method for the cache node: whether to use a hash - -                     <value>True</value> -                 </ Property> in                 < Propertyname= "ConnectionPoolSize"> -                     <value>1</value> to                 </ Property> +                 < Propertyname= "Optimizeget"> -                     <value>False</value> the                 </ Property> *                 < Propertyname= "Optimizemergebuffer"> $                     <value>False</value>Panax Notoginseng                 </ Property> -                 < Propertyname= "Mergefactor"> the                     <value>50</value> +                 </ Property> A                 < Propertyname= "Usebinaryprotocol"> the                     <value>True</value> +                 </ Property> -                 < Propertyname= "ConnectionTimeout"> $                     <value>2000</value> $                 </ Property> -                 < Propertyname= "Operationtimeout"> -                     <value>1000</value> the                 </ Property> -                 < Propertyname= "Enableheartbeat">Wuyi                     <value>True</value> the                 </ Property> -                 < Propertyname= "Failuremode"> Wu                     <value>False</value> -                 </ Property> About             </Bean> $         </ Property> -             <!--the cache name of the memcached configuration when there are multiple memcached in an app, the cachename of each configuration must be different. If this value is not set, the system defaults to default - -         < Propertyname= "CacheName"value= "Default" /> -     </Bean> A  +     <Beanclass= "Com.google.code.ssm.Settings"><!--this thing after 3.2, the document can be specified in order and the interceptor executes before and after--! Temporarily useless, plus no error - the         < Propertyname= "Order"value= "$" /> -     </Bean>     $ </Beans>

Finally in the code, add

1     /**2 * Get order information based on order number3      * @paramOrdernum4      * @return5      */6@ReadThroughSingleCache (Namespace = "Test", expiration = 30000)7      PublicOrder getorder (@ParameterValueKeyProvider String ordernum) {8SYSTEM.OUT.PRINTLN ("Cache not hit");9         return  This. Orderdao.getorder (ordernum);Ten}

There are many annotations to use, and here is not one to say. Where the cache is using my locally installed memcached. The project runs, and the first time you look up an order, it prints the message that the cache didn't hit, and the second time you don't see it. The cache was built successfully.

Simple-spring-memcached Cache Setup

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.