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
2
votes
2 answers

Spring Memcached annotations not Caching

I'm trying to get Memcache working in Spring. I've setup a local Memcached server using Docker and Kitematic: I can access the Memcached server using telnet: telnet 192.168.99.100 32780 and then run stats or stats items (which only prints out END…
Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137
2
votes
1 answer

Spring cache using memcached

I'm using https://github.com/AKQABER/simple-spring-memcached to have memcached integrated as a cache implementation with spring. But I'had no success :P I'm using spring 4 and spring-data-jpa public interface FooRepository extends JpaRepository
2
votes
2 answers

What is this error in spring mvc integrated via memcache

I want to use simple-spring-memcached to cache data. so using this https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started for my purpose. i add in my dispatcher-servlet.xml
Emil
  • 423
  • 1
  • 12
  • 34
2
votes
1 answer

How to use simple-spring-memcached with AWS Auto Discovery

How to use simple-spring-memcached library (SSM) with AWS Elasti Cache Auto Discovery feature? We are using spymemcached as client.
1
vote
2 answers

Invalidate entire namespace using Simple Spring Memcached

Has anyone tried invalidating an entire memcached namespace? For example I have two reads methods having differents keys @Override @ReadThroughSingleCache(namespace = UrlClientExclusion.TABLE_NAME, expiration = 24 * HOUR) public…
1
vote
3 answers

Unable to get good example of using memcached from Java boot

I am using java boot for my development. For now I have used 'EhCache' for caching , it is directly supported from Java boot. This is "in-process" cache, i.e., becomes part of your process. It is okay for now. But my server will run on multiple…
1
vote
2 answers

Simple Spring Memcached - how to add objects without any expiration

I am using SSMCache to store some objects in my application. I am adding the SSMCache object to my CacheManager like below : @Bean @Override public CacheManager cacheManager() { Set ssmCacheSet = new HashSet<>(); try { …
v1shnu
  • 2,211
  • 8
  • 39
  • 68
1
vote
1 answer

Spring MemCached flush all strange behaviour

In a spring web project, if we are using a single cache server and different cache managers an eg annotation is @Cacheable(value = "configCache", key="#key") @Cacheable(value = "envCache", key="#key") ... and if we do @CacheEvict(value =…
Ahmed
  • 636
  • 1
  • 14
  • 31
1
vote
1 answer

JSON serialization with simple spring memcached

I'm unable to use simple-spring-memcached with default serialization type set to JSON. The error I get is: java.lang.IllegalArgumentException: Cannot use JSON serialization because dedicated cache transcoder is null! at…
Gagan
  • 135
  • 1
  • 1
  • 11
1
vote
1 answer

Setting annotation based SpyMemcached configuration in spring mvc

I am new to spring framework. I want to use spy memcached in my application, but i cant find the proper annotation based configuration to set the bean. Currently i am using Memcached static object in my Controller which looks really bad programming.…
1
vote
2 answers

Spring mvc and memcache

I am using memcached to act according to what they've said in the address: https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started . The memcache on the server where it is done , I've installed . The library should be required to have…
Hadi J
  • 16,989
  • 4
  • 36
  • 62
1
vote
2 answers

spring-simple-memcache - maven dependencies for ReadThroughSingleCache

Has anyone used spring simple memcached? I have not been able to get the exact maven dependency and the repository where this is available. The dependencies mentioned on the code.google page (http://code.google.com/p/simple-spring-memcached/)…
gotz
  • 539
  • 2
  • 8
  • 23
0
votes
1 answer

Cache object only if it is Serializable

I have enabled Caching by using @Cacheable annotation on a method which has the following declaration: @Cacheable(value = "myCache", key = "#t+ '_' + #key", condition = "#key != null") public T get(String t, VendorProperty key, T…
Akhil Prajapati
  • 1,221
  • 3
  • 14
  • 23
0
votes
1 answer

InterruptedException during put operation SSM Xmemcached

We have a dedicated server as memcached. It has below configuration: STAT curr_connections 242 STAT total_connections 684 STAT chunk_size 48 STAT num_threads 64 STAT num_threads_per_udp 64 But we are seeing InterruptedException exception for a…
PVJ
  • 79
  • 3
  • 9
0
votes
1 answer

Memcached @cacheable does not cache

I am using Simple Spring Memcached (SSM) with my spring boot application. I am new to memcached and am trying to understand things. For the below code @RestController public class TestController { @RequestMapping(value = "/checkend", method =…
Pradeep
  • 850
  • 2
  • 14
  • 27
1
2