首页 > 应用开发 > Java > soringboot ehcache 配置和用法
1.pom
2. application.properties
3. 在resources目录下放一个文件 ehcache.xml
4.读取缓存 在 serviceImpl 层,例:MenuServiceImpl
加入的注解 @Cacheable(key="'menu-'+#parentId",value="menucache") ,其中 key="'menu-'+#parentId" 是指相应的键,#parentId 是通配符,和参数名对应,key 也可以是固定的字符, value="menucache" 中的 menucache 是 ehcache.xml中缓存策略中的name
5.清除缓存,也在在 serviceImpl 层,例:MenuServiceImpl
加入注解 @CacheEvict(value="menucache", allEntries=true)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31558068/viewspace-2769714/ ,如需转载,请注明出处,否则将追究法律责任。