2008-02-02
spring ehcache 配置以及使用
ehcache.xml
applicationContext.xml
*dao.java
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<cacheManagerEventListenerFactory class="" properties=""/>
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,
multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=1"
propertySeparator=","
/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="120"
overflowToDisk="true"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> </props> </property> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean>
*dao.java
public List retrieveTradeDomainByTypeAndNumber(final String type, final Integer number) {
return (List) getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(TradeDomain.class);
criteria.add(Restrictions.like("sdtype", type, MatchMode.ANYWHERE));
criteria.setMaxResults(number);
criteria.setCacheable(true);
return criteria.list();
}
},true);
}
发表评论
- 浏览: 13483 次
- 性别:

- 来自: 江苏

- 详细资料
搜索本博客
我的相册
100_0721
共 1 张
共 1 张
最近加入圈子
链接
最新评论
-
hibernate 随记二(一对多 ...
这样做肯定没得问题,用query.createQuery()方法做也没有问题 返 ...
-- by javaman1982 -
hibernate 随记二(一对多 ...
[color=red][/color]
-- by HH -
(特殊字符)怎么处理 类 ...
谢谢各位得回答..看来偶水平还很菜
-- by zhkchi -
(特殊字符)怎么处理 类 ...
什么啊?好像没看懂lz的意思,但<c:out value="${}" es ...
-- by SteveGY -
(特殊字符)怎么处理 类 ...
好了... 不知道为什么jstl标签c不行 我直接用request.getA ...
-- by zhkchi






评论排行榜