映射的Spring缓存退出

映射的Spring缓存退出,spring,memcached,Spring,Memcached,我有下面的缓存方法 @Override @Cacheable(value = { "timeCache" }) public Map<String, RechargeMatrix> getValues() { ..... } 上述代码未清除缓存值。。我觉得我必须为逐出某个特定值提供入口键值。但是说clearCache(“12345”);将不起作用,因为它正在查找字符串值而不是键值。 但是别忘了怎么交钥匙。。 有线索吗 thanks

我有下面的缓存方法

    @Override
    @Cacheable(value = { "timeCache" })
    public Map<String, RechargeMatrix> getValues() {
         .....
    }
上述代码未清除缓存值。。我觉得我必须为逐出某个特定值提供入口键值。但是说clearCache(“12345”);将不起作用,因为它正在查找字符串值而不是键值。
但是别忘了怎么交钥匙。。 有线索吗

thanks in advance

您可以做的是清除并立即重新缓存您的timeCache,例如,您的clearCache方法应修改如下所示:

@CacheEvict(value = "timeCache", allEntries = true, beforeInvocation = true)
@Cacheable("timeCache")
public Map<String, RechargeMatrix> clearAndRecache() {
    // retrieve your timeCache values as in getValues() method
}
@cacheexecute(value=“timeCache”,allEntries=true,beforecocation=true)
@可缓存(“时间缓存”)
公共地图ClearCache(){
//在getValues()方法中检索时间缓存值
}
您可以在示例项目中检查这一点。此示例基于

更新:

如果您需要key参数,如clearCache(字符串键)删除数据库中的数据,那么您的代码应该如下所示:

@CacheEvict(value = "timeCache", allEntries = true, beforeInvocation = true)
@Cacheable(value = "timeCache", key = "T(org.springframework.cache.interceptor.SimpleKey).EMPTY")
public Map<String, RechargeMatrix> deleteAndRecache(String key) {
    // 1. delete data in DB by key parameter 
    // 2. retrieve your timeCache values as in getValues() method and return it
}
@cacheexecute(value=“timeCache”,allEntries=true,beforecocation=true)
@可缓存(value=“timeCache”,key=“T(org.springframework.cache.interceptor.SimpleKey.EMPTY”)
公共映射缓存(字符串键){
//1.按关键参数删除数据库中的数据
//2.在getValues()方法中检索timeCache值并返回它
}

所有这一切的原因是getValues()方法将数据缓存在memcached中,其中键的值为
SimpleKey.EMPTY
。因此,此方法中返回的映射应该具有相同的键值

请修改格式。感谢您的解决方案。:)
@CacheEvict(value = "timeCache", allEntries = true, beforeInvocation = true)
@Cacheable(value = "timeCache", key = "T(org.springframework.cache.interceptor.SimpleKey).EMPTY")
public Map<String, RechargeMatrix> deleteAndRecache(String key) {
    // 1. delete data in DB by key parameter 
    // 2. retrieve your timeCache values as in getValues() method and return it
}