我正在尝试在我的spring项目中配置咖啡因。通过阅读guide,,我可以看到有多种方法可以将其配置到您的应用程序中,从创建缓存管理器bean到显式地在application.yml属性文件中写入配置。
到目前为止,我已经使用application.yml方法来配置我的咖啡因缓存:
spring:
cache:
type: Caffeine
cache-names: test1
caffeine:
spec: maximumSize=500, expireAfterAccess=30s我在一个控制器方法中使用了@Cachable注解:
@GetMapping
@Cacheable(value = "test1", key = "#accountId")
public DTOStatus getStatus(@PathVariable String accountId) {
if (statusChecker.equals(Check.REQUIRED)) {
deleteAccountFromCache(accountId);
return transformDTO(statusChecker);
} else {
return transformDTO(statusChecker);
}
}
@CacheEvict(value = "test1", key = "#accountId")
public void deleteAccountFromCache(String accountId){
//Method body left blank. The annotation deletes the accountId from the cache.
}我想知道我是否正确地配置了缓存。我现在不能测试它,但只想确保我已经完成了启用咖啡因的所有必要步骤
发布于 2019-07-08 21:39:08
例如,还要在您的配置java类中添加org.springframework.cache.annotation.EnableCaching注释。
@EnableCaching
class ApplicationConfig {https://stackoverflow.com/questions/56932729
复制相似问题