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
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).
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 @SpringBootApplication
this annotation put this
@EnableMemcached
Then in your Component use the following
@Autowired
private MemcachedClient memcachedClient;
memcachedClient.get("...")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With