ibatis cache不起作用

liuwei_blog 2011-01-13 04:19:18
sqlMapConfig:
<settings cacheModelsEnabled="true" statementCachingEnabled="true" enhancementEnabled="true"
lazyLoadingEnabled="true" errorTracingEnabled="true"
useStatementNamespaces="true" />

sqlMap:
<cacheModel id="indCache" type ="OSCACHE" > 
<flushInterval hours="24"/>
</cacheModel>

<select id="getHistory" parameterClass="java.util.HashMap" resultClass="Ind" cacheModel="indCache">
select ..
</select>

</sqlMap>

oscache.properties:
cache.memory=true
cache.key=_oscache_cache
cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
cache.capacity=1000

控制台输出:
[DEBUG] 2011-01-13 16:00:30,765 [btpool0-1] com.ibatis.sqlmap.engine.cache.CacheModel - Cache 'Ind.indCache': cache miss
[DEBUG] 2011-01-13 16:02:23,218 [btpool0-1] com.ibatis.sqlmap.engine.cache.CacheModel - Cache 'Ind.indCache': stored object 'com.studio.domain.Ind@b37df5, com.studio.domain.Ind@129aa7, com.studio.domain.Ind@1677e4b, com.studio.domain.Ind@19496a7, com.ihandy.yuncai.studio....'
[DEBUG] 2011-01-13 16:07:36,531 [btpool0-1] com.ibatis.sqlmap.engine.cache.CacheModel - Cache 'Ind.indCache': cache miss
[DEBUG] 2011-01-13 16:09:29,015 [btpool0-1] com.ibatis.sqlmap.engine.cache.CacheModel - Cache 'Ind.indCache': stored object 'com.studio.domain.Ind@deda0b, com.studio.domain.Ind@bd286c, com.studio.domain.Ind@a8d724, com.studio.domain.Ind@c4925d, com.ihandy.yuncai.studio.mo...'

每次访问都是cache miss
请高手指点一二.
...全文
303 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuwei_blog 2011-01-17
  • 打赏
  • 举报
回复
由于条件里有日期且精确到毫秒(new Date()),所以每次查询条件都不"equals",将查询条件日期的时分秒毫秒都设为0(因为数据库里字段精确到天,这里这个条件精确到天),缓存就起作用了.^_^
happyfmy 2011-01-14
  • 打赏
  • 举报
回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧