我的代码结构如下
@Component
Class A{
@Autowired
B b;
public void getResponseFromB(){
b.getResponse("ABC");
}
}
@Service
Class B{
@Cacheable(value="myCaching", key="#cachingKey")
public String getResponse(String cachingKey){
return "sample";
}
}
@Configuration
@EnableCaching
Class GuavaCaching{
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
GuavaCache guavaCache1 = new GuavaCache("myCaching", CacheBuilder.newBuilder()
.maximumSize(100).expireAfterWrite(1, TimeUnit.DAYS).build());
cacheManager.setCaches(Arrays.asList(guavaCache1));
return cacheManager;
}
}
我的问题是每次我从A调用类B的方法时,缓存均不起作用。我不确定我在这里缺少什么。任何线索都将不胜感激。