How to Configure Spring Boot with Memcached

Rahul :

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

Rahul Singh :

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("...")

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=466769&siteId=1
Recommended