我将redis用作缓存层,在那儿,我有很多地方在不同的服务和层中使用@Cacheable。
这是示例代码:
buildscript {
repositories {
jcenter()
google() //Add this repo
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
}
allprojects {
repositories {
jcenter()
google() //Add this repo
}
}
应用程序和缓存工作正常,但是当我使用以下命令获取redis-cli中的所有键时:
@Cacheable(value = "my_detail", key = "'m_detail_'+#entityIdd")
public InstituteDetail getMyDetail(Long entityId) {
call1();
call2()
}
@Cacheable(value = "call_1", key = "'call_1'+#entityIdd")
public InstituteDetail getMyDetail1(Long entityId) {
//some code
}
@Cacheable(value = "call_2", key = "'call_2'+#entityIdd")
public InstituteDetail getMyDetail2(Long entityId) {
//some code
}
它仅显示呼叫_1和呼叫_2的键。 并且不显示“ my_detail”的密钥。
这很奇怪,没有解决。任何建议,这是怎么了。
答案 0 :(得分:0)
生成了一个代理类,该类拦截所有请求并以缓存的值进行响应,仅拦截通过代理传入的外部方法调用。这意味着在目标对象内调用同一目标对象的另一个方法,即使调用的方法标记有@Cacheable
,也不会在运行时导致实际的缓存拦截。
因此如果该方法调用相同类的其他方法,则不能将'my_detail'值存储在缓存中。