@EnableCaching
• @Cacheable
指定一个或多个Cache名字,同属性cacheNames
Spring Cache 使用 ---@EnableCaching @Cacheable 注解

@Cacheable(value ="sampleCache")
@Cacheable(cacheNames="sampleCache")

• @CacheEvict
用于仅清除缓存
例子里的注解 @CacheEvict 中存在有以下几个元素 
- value (也可使用 cacheNames) : 同Cacheable注解,可看做命名空间。表示删除哪个命名空间中的缓存 
- allEntries: 标记是否删除命名空间下所有缓存,默认为false 
- key: 同Cacheable注解,代表需要删除的命名空间下唯一的缓存key。
第一段,与 @Scheduled 注解同时使用,每十秒删除命名空间name下所有的缓存。
第二段,调用此方法后删除命名空间models下, key == 参数 的缓存 同样含有unless与condition

@CacheEvict(value = "models", allEntries = true)
@Scheduled(fixedDelay = 10000)
public void deleteFromRedis() {
} @CacheEvict(value = "models", key = "#name")
public void deleteFromRedis(String name) {
}

• @CachePut
用于仅存放缓存
例子里的注解 @CachePut 中存在有以下几个元素
value: 同上
key: 同上
condition(unless): 同上
比如可用于后台保存配置时及时刷新缓存。
SpringCache缓存初探

@CachePut(value = "models", key = "#name")
public TestModel saveModel(String name, String address) {
return new TestModel(name, address);
}

• @Caching
用于在一个方法或者类上同时指定多个Spring Cache相关的注解

@Caching(cacheable = {@Cacheable(value = "userCache", key = "#a0", unless = "#")
,@Cacheable(value = "userCache", key = "#a0", unless = "#")})

• @CacheConfig
这个注解是用于在同一个类中共享一些基础的cache配置的
一个类级别的注解,允许共享缓存的名称、KeyGenerator、CacheManager 和CacheResolver。 
该操作会被覆盖。

//开启缓存注解

@Configuration
@EnableCaching
public class AppConfig {
}

最新文章

  1. jquery.extend
  2. Lintcode 375.克隆二叉树
  3. dojo.publish 和 dojo.subscribe
  4. Ubuntu 下使用Remmina Remote Desktop client 连接windows server输入法的问题
  5. linux 批量重命名文件
  6. iOS开发中打开本地应用、打开appStore应用、给app评分功能实现
  7. 纯CSS实现三列DIV等高布局
  8. Java批处理操作
  9. [Hadoop] - 自定义Mapreduce InputFormat&OutputFormat
  10. asp.net web api 构建api帮助文档
  11. 【react】---17新增的生命周期
  12. Spring 使用介绍(八)—— 零配置(一)
  13. MultipartFile(文件的上传)
  14. C# 1.0 到 4.0 的进化 1
  15. ss客户端的使用
  16. QT TCP网络编程
  17. 硬盘坏道检测工具对比(DiskGenius/HdTunePro/MHDD等)
  18. 转:只能选择GridView中的一个CheckBox(单选CheckBox)
  19. 关于mvn install命令执行报错问题
  20. 【【模板】严格次小生成树[BJWC2010]】

热门文章

  1. python基础语法之集合set
  2. echarts 饼图-->如何修改legend模板?
  3. udb
  4. java实现顺序队列
  5. LeetCode_9_回文数字
  6. Python爬虫之简单的爬取百度贴吧数据
  7. js中this.index使用
  8. Action实现prepareable接口后定义前置方法
  9. Git 设置 用户名 和 邮箱
  10. 利用ab压力工具对服务器进行压力测试