Simple-spring-memcached

Source: Internet
Author: User

Introduction

Distributed cache can be large and complicated when we use it extensively.

Simple-Spring-Memcached (SSM) implements some basic functions.

This project enables the cache to be locked and managed by spring bean containers. By using Java 5 annotations and Spring/AspectJ AOP on spymemcached or xmemcached client.

To use Simple-Spring-Memcached, you only need a little configuration and some annotations on the method.

Dependencies

Of course, you need at least one running memcache service. (Installation and usage instructions may be found on the memcached project page .)

Second, you need the Simple-Spring-Memcached JAR File

For spymemcached add dependency:

<dependency>  <groupId>com.google.code.simple-spring-memcached</groupId>  <artifactId>spymemcached-provider</artifactId>  <version>3.2.0</version></dependency>

For xmemcached add dependency:

<dependency>  <groupId>com.google.code.simple-spring-memcached</groupId>  <artifactId>xmemcached-provider</artifactId>  <version>3.2.0</version></dependency> 
Configuration

What you need to tell youApplicationContextThe Simple-Spring-Memcached configuration uses an import command

<import resource="simplesm-context.xml" />

This xml file can be obtained in the simple-spring-memcached-3.2.0.jar

Simple-Spring-Memcached also requires defining the AOP namespace to use the annotation of aop.

<beans xmlns="http://www.springframework.org/schema/beans"     xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemaLocation="http://www.springframework.org/schema/aop              http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  <aop:aspectj-autoproxy />       </beans>

To tell Simple-Spring-Memcached your specific environment, you need to configure the Default client

  • Spymemcached:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:aop="http://www.springframework.org/schema/aop"        xsi:schemaLocation="           http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd           http://www.springframework.org/schema/aop            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  <import resource="simplesm-context.xml" />  <aop:aspectj-autoproxy />   <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">    <property name="cacheClientFactory">      <bean name="cacheClientFactory" class="com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl" />    </property>    <property name="addressProvider">      <bean class="com.google.code.ssm.config.DefaultAddressProvider">        <property name="address" value="127.0.0.1:11211" />      </bean>    </property>    <property name="configuration">      <bean class="com.google.code.ssm.providers.CacheConfiguration">        <property name="consistentHashing" value="true" />      </bean>    </property>  </bean></beans>

  

  • Xmemcached:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:aop="http://www.springframework.org/schema/aop"        xsi:schemaLocation="           http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd           http://www.springframework.org/schema/aop            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  <import resource="simplesm-context.xml" />  <aop:aspectj-autoproxy />    <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">    <property name="cacheClientFactory">      <bean name="cacheClientFactory" class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />    </property>    <property name="addressProvider">      <bean class="com.google.code.ssm.config.DefaultAddressProvider">        <property name="address" value="127.0.0.1:11211" />      </bean>    </property>    <property name="configuration">      <bean class="com.google.code.ssm.providers.CacheConfiguration">        <property name="consistentHashing" value="true" />      </bean>    </property>  </bean></beans>

The spymemcached or xmemcached client implements the consistentHashing algorithm and uses the consistentHashing parameter to determine which node is written data.

Usage

To understand the usage of memcache, first understand the key and value.

Order of cache advice

Since 3.2.0 SSM cache advice runs before transaction advice. The default SSM cache advice order value is 0. The order can be set in the application context file to any custom value:

<beanclass="com.google.code.ssm.Settings">  <propertyname="order"value="500"/></bean>

  

 

 

 

 

 

 

 

 

 





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.