1、增加缓存
@Cacheable(value = "auditIsDateOutCache", key = "#companyId")
public Map<String, Object> findAuditIsDateOut(Long companyId) {}
value :缓存的名称,必须有一个,可以多个{“”,“”}
key:指定缓存的key值,删除也可以根据该key (不是必须项)
2、删除缓存
(1)、
@CacheEvict(value = { "menuIdsCache", "leftMenuCache" }, allEntries
= true)
public void saveStartAuditByParam() {}
(2)、
@CacheEvict(value = {"stageProgressCache", "findAuditIsExistCache" }, key
= "#userId")
public void saveStartAuditByParam( Long
userId) {}
1、allEntries = true 清空所有的缓存
2、key = "#userId" 指定键值,清空缓存
3、组合缓存
@Caching(
evict = {
@CacheEvict(value = "leftMenuCache", allEntries = true),
@CacheEvict(value = {"stageProgressCache", "findAuditIsExistCache" }, key = "#userId"),
@CacheEvict(value = "auditIsDateOutCache" , key="#param.getCompanyId()"),
}
)
public void saveStartAuditByParam(AuditStartParam param, Long userId){}
本文深入探讨了在编程中使用缓存的策略,包括如何增加、删除和组合缓存,以提高应用性能。详细解释了缓存名称、键设置及其作用,并提供了实例代码演示。此外,介绍了如何通过组合缓存方法来更高效地管理和释放资源。
763

被折叠的 条评论
为什么被折叠?



