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
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
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
Add this to your Gradle Dependencies
On top of your main Spring boot application where you
@SpringBootApplication
this annotation put thisThen in your Component use the following
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.The configuration in the
application.yml
can be as simple as: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).