cacheable更新_@Cacheable不会拦截该方法,缓存始终为空

我有如下方法:

@Cacheable(value = "SAMPLE")

public List find() {

// Method that initiates and returns the List and takes around 2-3 seconds, does some logging too

}

我在其中一个配置类中启用了缓存:

@EnableCaching

@Configuration

public SomeConf extends CachingConfigurerSupport {

// Here I also initialize my classes with @Cacheable annotation

@Bean

@Override

public CacheManager cacheManager() {

SimpleCacheManager cacheManager = new SimpleCacheManager();

cacheManager.setCaches(Collections.singletonList((new ConcurrentMapCache("SAMPLE"))));

return cacheManager;

}

@Bean

@Override

public CacheResolver cacheResolver() {

return new SimpleCacheResolver(cacheManager());

}

@Bean

@Override

public KeyGenerator keyGenerator() {

return new SimpleKeyGenerator();

}

}

我的内容如下pom.xml:

org.springframework.boot

spring-boot-starter-cache

1.5.14.RELEASE

我声明CacheManager如下:

@Bean

public CacheManager cacheManager(){

SimpleCacheManager cacheManager = new SimpleCacheManager();

cacheManager.setCaches(Collections.singletonList((new ConcurrentMapCache("SAMPLE"))));

return cacheManager;

}

当我将一个@Autowired

CacheManager实例放入其中一个实例时,我@Service可以看到存在一个名为name的缓存"SAMPLE",但其条目始终为空。我一次又一次地调用方法find(),但是它似乎并未填充缓存。

我试图把一个参数(比如int a)的find()方法,并把它作为key = "#a"对@Cacheable的,但什么都没有改变。

当我尝试在隔离的环境中重新创建问题时,可以看到它正常运行。但是,当我添加我的依赖项(非开源公司库,其中也包括EhCache配置)时,它不起作用。我该如何调试,我在做什么错?

更新:

我也试图利用cacheManager = myCacheManager在@Cacheable为好。没运气。

更新2:

我正在使用AspectJSpring AOP。我认为这可能与它有关。我已经尝试过@EnableCaching(mode =

AdviceMode.ASPECTJ),@EnableLoadTimeWeaving但同样的事情。

更新3:

基本上,当您运行该应用程序telnet localhost 9000并向其发送任何行之后,NOT

CACHED即使该方法被两次调用CachedController(第二次来自缓存),它也应该打印一次。但是它打印两次。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值