BAEL-6250: Example code for Get All Caffeine Cache Keys article (#13806)

This commit is contained in:
Grzegorz Musiał
2023-05-10 13:38:19 +02:00
committed by GitHub
parent 1ff112228c
commit a36b4d88b7
3 changed files with 80 additions and 0 deletions
@@ -0,0 +1,25 @@
package com.baeldung.allkeys.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.allkeys.service.SlowServiceWithCache;
@Configuration
@EnableCaching
public class AllKeysConfig {
@Bean
SlowServiceWithCache slowServiceWithCache() {
return new SlowServiceWithCache();
}
@Bean
CacheManager cacheManager() {
return new CaffeineCacheManager();
}
}
@@ -0,0 +1,11 @@
package com.baeldung.allkeys.service;
import org.springframework.cache.annotation.CachePut;
public class SlowServiceWithCache {
@CachePut(cacheNames = "slowServiceCache", key = "#name")
public String save(String name, String details) {
return details;
}
}