spring ehcache 配置以及使用

ehcache.xml


<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);
	}

你可能感兴趣的:(java,DAO,spring,Hibernate,xml)