ssh框架加入oscache

拷oscache-2.4.1.jar到WEB-INF/lib下面,添加oscache.properties文件到classes,oscache.properties文件配置可以参考oscache-2.4.1-full.zip包里面的oscache.properties文件.

1、hibernate使用OSCache

在spring配置文件,session bean的hibernateProperties属性添加:

<prop key="hibernate.current_session_context_class">thread</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.provider_class">com.opensymphony.oscache.hibernate.OSCacheProvider</prop>
                <prop key="hibernate.jdbc.batch_size">25</prop>

在*.hbm.xml文件中添加<cache usage="read-only"/>

2、ibatis中使用OSCache

在sql-map-config.xml文件<sqlMapConfig>树下配置<settings cacheModelsEnabled="true" lazyLoadingEnabled="true" enhancementEnabled="true" errorTracingEnabled="true"/>

xml映射文件中添加:

<cacheModel id="userCache" type="OSCACHE">
  <!-- 24小时强制清空缓冲区的所有内容 -->
  <flushInterval hours="24"/>
  <!-- 指定执行特定的statement时,将缓存清空 -->
  <flushOnExecute statement="update_user" />
   <!-- cache的最大容积 -->  
  <property name="size" value="1000" />
 </cacheModel>

statement语句中指定要使用的缓存:

<select id="findUserByDept" parameterClass="java.util.HashMap" resultClass="java.util.HashMap" cacheModel="userCache">

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值