Questions tagged [simple-spring-memcached]

Enables caching in Spring-managed beans, by using Java Annotations and Spring/AspectJ AOP on top of the spymemcached, xmemcached or aws-elasticache client. Can work as a cache back-end for memcached in Spring Cache abstraction (@Cacheable).

Introduction

Distributed caching can be a big, hairy, intricate, and complex proposition when using it extensively.

Simple Spring Memcached (SSM) attempts to simplify implementation for several basic use cases.

(2015-06-09) New version 3.6.0 with Amazon ElastiCache support is available! Since version 3.0.0 it can work as a cache back-end for Spring Cache (@Cacheable). Please check release notes.

This project enables caching in Spring-managed beans, by using Java 5 Annotations and Spring/AspectJ AOP on top of the spymemcached or xmemcached client. Using Simple Spring Memcached requires only a little bit of configuration and the addition of some specific annotations on the methods whose output or input is being cached.

Usage

If you are using maven, you can try it now:

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

and define connection to memcached on localhost:

<beans xmlns="http://www.springframework.org/schema/beans" 
    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 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>

Now you can annotate method to cache result:

@ReadThroughSingleCache(namespace = "CplxObj", expiration = 3600)
public ComplexObject getComplexObjectFromDB(@ParameterValueKeyProvider Long complexObjectPk) {
  // ...
  return result;
}

If you already using Spring Cache you may use SSM as an another back-end.

If you are not using maven you can download current SSM distribution from github.

References

Github project

24 questions
0
votes
1 answer

"client not initialized" error when using SSMCache with AWS elasticache autodiscovery

I am using Spring cache with AWS elasticache provider. I get this warning: WARN c.g.code.ssm.spring.SSMCache - An error has occurred for cache defaultCache and key java.lang.IllegalStateException: Client is not initialized at…
0
votes
1 answer

ssm simple-spring-memcached - cache write not working

I am using the SSMCache#put API directly to get a cache and update on a key. Intially I have read the value from cache using below spring-cache annotated method. @Cacheable(value="CACHE_JOURNALS", key="#ID") public JournalBean…
JayabalanAaron
  • 360
  • 3
  • 13
0
votes
1 answer

How to handle code when memchache is not working(simple-spring-memcached)

Thanks to the 'Getting started guide' in ‘simple-spring-memcached’ I manage to get memcached working in my project using ‘Spring 3.1’ example in in the guide , Im using ‘spymemcached’ as the provider . All working well when memcached server is up…
csf
  • 529
  • 1
  • 4
  • 16
0
votes
1 answer

how to cache collection or array parameters with simple-spring-memcache

My project use a simple-spring-memcache to caching a service method, but it does't work, as follows: @ReadThroughSingleCache(namespace = "AdvServiceImpl.findByIdList", expiration = 60) public List findByIdList(@ParameterValueKeyProvider(order =…
justlee
  • 13
  • 1
0
votes
1 answer

How to configure Simple Spring Memcached to work with Couchbase

I'm developing a Spring MVC application, and I'd like to set up caching using Simple Spring Memcached (SSM) with a Couchbase backend. I have setup a working couchbase install locally, with a memcache bucket "default". I can connect and use the…
0
votes
1 answer

How to flush all the cache entries in simple spring memcached

This question is with reference to Simple Spring memcached. I have a scenario where a list of deals are cached for user using the userId as the key. Now in case a deal data is updated I need to flush the cache for all users since this would affect…
0
votes
1 answer

Difference between singlecache, multicache and assigncache with respect to spring memcached annotations

I am trying to understand the Simple Spring Memcached but have stuck with below mentioned. What is the difference between: @ReadThroughSingleCache, @ReadThroughMultiCache and @ReadThroughAssignCache @UpdateSingleCache, @UpdateMultiCache and…
0
votes
1 answer

How to specify different cache keys on the same key object in simple-spring-memcached

I am trying to implement a distributed cache with spring-memcached. The docs suggest that to use an object as the key I need to have a method in my domain class with @CacheKeyMethod annotation on it. But the problem is I am using the same domain…
0
votes
1 answer

Invalidating namespace using simple spring memcached

Has anyone tried invalidating a memcached namespace based on timestamp? For e.g. I need to have a memcached namespace which is the timestamp of the tomcat server that hosts my API services. I need to annotate my method calls so that the namespace…
gotz
  • 539
  • 2
  • 8
  • 23
1
2