9.使用高速缓存提高性能
来源:互联网 发布:淘宝正品代购 编辑:程序博客网 时间:2024/06/05 20:56
1. 一个简单的ibatis高速缓存示例
<cacheModel id="categoryCache" type="MEMORY"><flushOnExecute statement="insert" /><flushOnExecute statement="update" /><flushOnExecute statement="delete" /><property name="reference-type" value="WEAK" /></cacheModel><select id="getCategory" parameterClass="Category" resultClass="Category"cacheModel="categoryCache">SELECT *FROM CategoryWHERE categoryId=#categoryId#</select>
2.ibatis高速缓存的理念
ibatis是一个以数据为中心的框架,关注的是SQL语句的执行结果,所以我们不会根据对象的唯一性来高速缓存他们ibatis高速缓存返回的所有结果,而不考虑所标识的对象是否存在于高速缓存中。
3 理解高速缓存模型
3.1 type属性
3.2 readOnly属性
用于告诉高速缓存模型应该如何检索和保存已高速缓存的对象。
3.3 serialize属性
用于指示高速缓存对象应该如何返回。
3.4 联合使用readOnly属性和serialize属性
4. 如何使用高速缓存模型中的标签
4.1 高速缓存的清除
<sqlMap namespace="Category">…<cacheModel id="categoryCache" type="MEMORY">…<flushOnExecute statement="Category.insert" />…</cacheModel>…<select id="getCategory" parameterClass="Category" resultClass="Category"cacheModel="categoryCache">SELECT *FROM CategoryWHERE parentCategoryId=#categoryId#</select>…<insert id="insert" parameterClass="Category">INSERT INTO Category(title,description,sequence)VALUES(#title#,#description#,#sequence#)</insert>…</sqlMap>
但是只允许指定一个属性。
4.2 设置高速缓存模型实现的特性
5. 高速缓存模型的类型
5.1 MEMORY
基于引用的高速缓存
MEMORY高速缓存类型只有一个特性,即reference-type,用于指定期望使用的引用类型。
<cacheModel id="categoryCache" type="MEMORY"><flushInterval hours="24" /><flushOnExecute statement="insert" /><flushOnExecute statement="update" /><flushOnExecute statement="delete" /><property name="reference-type" value="WEAK" /></cacheModel>
5.2 LRU
使用最近最少使用策略管理高速缓存。
大小限制定义了高速缓存中可以包含的对象数目。避免将那些大的内存对象放置在此类高速缓存中。
<cacheModel id="categoryCache" type="LRU"><flushInterval hours="24" /><flushOnExecute statement="insert" /><flushOnExecute statement="update" /><flushOnExecute statement="delete" /><property name="size" value="200" /></cacheModel>
5.3 FIFO
先进先出管理策略。大小限制定义了高速缓存中可以包含的对象数目。避免将那些大的内存对象放置在此类高速缓存中。
<cacheModel id="categoryCache" type="FIFO"><flushInterval hours="24" /><flushOnExecute statement="insert" /><flushOnExecute statement="update" /><flushOnExecute statement="delete" /><property name="size" value="1000" /></cacheModel>
5.4 OSCACHE
对OSCache JAR文件依赖。oscache.properties文件 放在类路径的根目录下
<cacheModel id="categoryCache" type="OSCACHE"><flushInterval hours="24" /><flushOnExecute statement="insert" /><flushOnExecute statement="update" /><flushOnExecute statement="delete" /></cacheModel>
5.5 自己的高速缓存模型
第一:以上4种高速缓存模型实际上是com.ibatis.sqlmap.engine.cache.CacheController接口的具体实现
第二:他们的名称实际上只是映射到这些实现的全限定名的别名
6. 确定高速缓存策略
6.1 高速缓存只读的长效数据
6.2 高速缓存可读写数据
6.3 高速缓存旧的静态数据
0 0
- 9.使用高速缓存提高性能
- 使用高速缓存
- 使用Epoll提高网络性能
- 使用缓冲IO提高性能
- 使用本地缓存提高性能
- 使用类共享提高性能
- hashMap使用中的性能提高
- hashMap使用中的性能提高
- 使用APR提高Tomcat性能
- -GCD的使用-提高性能
- php使用memcache提高性能
- ListView使用ViewHolder提高性能
- 使用oscache提高程序性能
- tomcat使用APR提高性能
- SqlCacheDependency的使用,高速缓存
- C#使用memcached高速缓存
- 高速缓存
- 高速缓存
- 释义
- kafka监控工具kafkaOffsetMoniter的使用
- 滑动门
- java反射机制详解 及 Method.invoke解释 getMethod
- BloomFilter检测实现代码
- 9.使用高速缓存提高性能
- UDP协议的两个主要方法sendto和recvfrom详解
- Java Security安全系列文档翻译笔记————数字签名、keystore、证书
- .exe 已触发了一个断点。
- Linux下mongodb安装及数据导入导出教程
- Android 广播
- Android光线传感器-android学习之旅(65)
- C#高效绘图(转)
- Seek the Name, Seek the Fame POJ 2752【KMP next数组的应用】