skip to Main Content

I am new to Memcached. I need to configure my spring boot application with Memcached.

I researched a lot on the topic but I could not find a documentation for the same.
By default Spring boot uses Concurrent HashMap for caching but how do I configure Memcached.

I got this GitHub URL but I am not sure if this is the correct way and if so how do I use the same.

https://github.com/sixhours-team/memcached-spring-boot

https://www.javacodegeeks.com/2013/06/simple-spring-memcached-spring-caching-abstraction-and-memcached.html

Update

I have used this in my project now https://github.com/bmatthews68/memcached-spring-boot-starter.

Like this

@Override @Cacheable(value = "defaultCache")
    public String customMethof() throws InterruptedException {
        return "Testing";
    }

but when i do a telnet of get defaultCache i get nothing Please help

3

Answers


  1. The first GitHub project you have shown is a good solution. It is also a fork a spymemcached which is one of the prominent client libraries of Memcached.

    Please refer the below official documentation.
    http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_caching

    You can also check the below one and traverse to Getting Started page.

    https://github.com/killme2008/xmemcached

    Login or Signup to reply.
  2. Add this to your Gradle Dependencies

    compile group: 'net.spy', name: 'spymemcached', version: '2.12.3'
    compile('com.btmatthews.springboot:memcached-spring-boot-starter:1.0.0')
    

    On top of your main Spring boot application where you @SpringBootApplicationthis annotation put this

    @EnableMemcached
    

    Then in your Component use the following

    @Autowired
    private MemcachedClient memcachedClient;
    
    memcachedClient.get("...")
    
    Login or Signup to reply.
  3. I’m one of the authors of the https://github.com/sixhours-team/memcached-spring-boot.
    The library will auto-configure Memcached within a Spring Boot application. You can enable it just as you would with Spring Cache i.e. it is sufficient to add the @EnableCaching annotation in your configuration class e.g.

    @Configuration
    @EnableCaching
    public class CacheConfiguration {
    }
    

    The configuration in the application.yml can be as simple as:

    memcached.cache:
       servers: example1.com:11211
       mode: static
       expiration: 86400
    

    At the moment, the library has not been released yet (the first release should be in about a week). You can find more info here or check the demo Spring Boot app here.

    One more thing, in order to support cache eviction, the library is prefixed with memcached:spring-boot:defaultCache:[radnom_number], so in your case the key would be something like e.g.

    memcached:spring-boot:books:defaultCache:283:SimpleKey[]

    where 283 is the random number assigned to the cache key (needed for the proper cache eviction).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search