springboot下及其方便的使用缓存
来源:互联网 发布:ubuntu虚拟机nat联网 编辑:程序博客网 时间:2024/05/18 19:39
缓存的提供商是:ehcache
只需要很少的代码就能实现缓存.
1 开启spring缓存
@EnableCachingpublic class XxxxApplication extends SpringBootServletInitializer{}
2 ehcache.xml中定义一个缓存
<?xml version="1.0" encoding="UTF-8"?><ehcache name="com.xxx.core.cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> <!-- 新定义一个查询类缓存. 常用的查询,也放进缓存,提升性能. 比如首页的几个查询 --> <cache name="com.xxx.QUERY_CACHE" maxElementsInMemory="1000" eternal="false" overflowToDisk="false" timeToIdleSeconds="3600000" timeToLiveSeconds="3600000" memoryStoreEvictionPolicy="LFU" /></ehcache>
3 指定缓存服务商
<bean id="springCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:/spring/ehcache.xml" /> <property name="shared" value="false" /> </bean> <bean id="serviceCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager"> <ref bean="springCacheManager" /> </property> </bean> <bean id="serviceCache" factory-bean="serviceCacheManager" factory-method="getCache"> <constructor-arg value="com.shopizer.OBJECT_CACHE" /> </bean>
4 代码中使用
@Cacheable(value="com.xxx.QUERY_CACHE")public List<ProductRelationship> getByType(MerchantStore store, String type, Language language)(当命中的时候,根本不进getByType这个方法的)
阅读全文
0 0
- springboot下及其方便的使用缓存
- springboot 使用缓存
- Springboot中使用缓存
- SpringBoot--使用Redis缓存
- Springboot中使用缓存
- SpringBoot--使用Redis缓存
- Ubuntu下方便使用的下载工具
- linux下方便的使用有道词典
- springboot的缓存技术
- springboot的缓存技术
- okhttp的详解及其缓存的使用
- Hibernate常用的缓存插件及其使用
- SpringBoot中使用数据缓存
- springboot 下使用Filter
- SpringBoot的数据缓存支持
- tp5的RBAC插件及其使用很方便的管理用户登录及操作权限
- 方便的使用Nunit
- SpringBoot中使用Redis实现缓存
- csp 2014_9_4 最优配餐
- Spark中groupByKey与reduceByKey算子之间的区别
- 蓝桥进制转换题集
- Python爬虫
- Log4j实例简单配置
- springboot下及其方便的使用缓存
- 算法-循环链表[约瑟夫问题]
- 内存初始化-----memset函数的使用
- 计算机语言发展史
- Java(8-1)
- Mysql02_索引
- CodeForces 888A Local Extrema
- 调试的错误就是编程给你最好的东西,因为在每个错误上面都标志着前进的一步
- AndroidStudio:Intel x86 Emulator Accelerator(HAXM installer) Not compatible with Windows?(171106