我使用@Cacheable注释和cacheManager它是一个SimpleCacheManager。所以我尝试用@CacheEvict排除所有条目,没有错误,但 resetProducts()方法不起作用。
Bean配置
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="produtos"/>
</set>
</property>
</bean>
ProductBO.java的方法
@Cacheable(value = "produtos", key = "#id + #page + #filtros.toString() + #regiaoCep", unless = "#result == null")
public List<? extends ProdutoTO> getProdutos(String id, List<String> filtros, Integer page, String cep, String regiaoCep) {
//Code
}
resetProducts
@Component
public class CacheConfig {
@CacheEvict(value = "produtos", allEntries = true)
public void resetProducts() {
}
}
动作
public class LojaConfigAction extends GenericAction {
@Autowired
CacheConfig cacheConfig;
public String eliminarCache() {
boolean b = true;
try {
cacheConfig.resetProducts();
String cache = getRequest().getParameter("cacheName");
CacheManager cm = CacheManager.create();
if (cache == null || cache.isEmpty() || cache.equalsIgnoreCase("TODOS")) {
cm.removalAll();
} else {
cm.removeCache(cache);
}
Print.out("Cache " + cache + " eliminado");
} catch (Exception e) {
b = false;
}
getRequest().setAttribute("html", b);
return "html";
}
//Methods
}
不幸的是,它是使用Apache Struts的遗留项目,所以我需要从这个struts动作调用CacheConfig。我做错了什么?