常见的缓存技术
ehcache:hibernate底层
memcache:
redis:常用
jar包:
360截图20190722191024047.jpg
ehcache使用步骤:
1.导入jar包
2.编写配置文件
3.使用api
获取数据先从缓存中获取
若获取的值为空
再去查询数据库,
将数据放入缓存中
public List findAll() throws Exception {
//1.创建缓存管理器
CacheManager cm=CacheManager.create(CategoryServiceImpl.class.getClassLoader().getResourceAsStream("ehcache.xml"));
//2.获取指定的缓存
Cache cache = cm.getCache("categoryCache");
//3.通过缓存获取数据 将cache看成一个map即可