(轉)在Spring框架中使用OSCache快取

iteye_19594發表於2013-07-15

版權宣告:轉載時請以超連結形式標明文章原始出處和作者資訊及本宣告
http://aumy2008.blogbus.com/logs/41706937.html

 

Spring框架中使用OSCache快取

       就是使用Spring提供的springmodulesOSCache來簡化程式的開發,通過配置檔案來完成提供快取。參考springmodules的文件。

 

1、建立Spring OSCache的配置xml檔案

2oscache.propertiesoscache.tld放入WEB-INF\class目錄,並修改屬性檔案的引數

 

       下邊Spring OSCache配置資訊來自http://www.iteye.com/problems/7493

<?xml version="1.0" encoding="UTF-8" ?>  

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">  

<beans>  

    <bean id="cacheManager" 

          class="org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">  

        <!-- Optional properties -->  

        <property name="configLocation" value="classpath:oscache_config.properties"/>  

    </bean>  

    <bean id="cacheProviderFacade" 

          class="org.springmodules.cache.provider.oscache.OsCacheFacade">  

        <property name="cacheManager" ref="cacheManager"/>  

    </bean>  

 

    <bean id="cacheKeyGenerator" class="org.springmodules.cache.key.HashCodeCacheKeyGenerator"/>  

 

    <bean id="userDaoProxy" 

          class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">  

        <property name="cacheProviderFacade" ref="cacheProviderFacade"/>  

        <property name="cacheKeyGenerator" ref="cacheKeyGenerator"/>  

        <property name="cachingModels">  

            <props>  

                <prop key="get*">refreshPeriod=12;groups=user</prop>  

            </props>  

        </property>  

        <property name="flushingModels">  

            <props>  

                <prop key="update*">groups=user</prop>  

                <prop key="delete*">groups=user</prop>  

                <prop key="add*">groups=user</prop>  

            </props>  

        </property>  

 

        <property name="cachingListeners">  

            <list>  

                <!--ref bean="cachingListener" /-->  

            </list>  

        </property>  

        <property name="target" ref="userDaoTarget"/>  

    </bean>  

 

 

   <bean id="userDaoTarget" class="com.logictown.BHT.dao.springJdbc.UserDaoImpl">  

        <property name="dataSource" ref="dataSource"/>  

    </bean>  

 

</beans> 

相關文章