在Spring框架中使用OSCache缓存

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
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> 

你可能感兴趣的:(DAO,spring,框架,bean,cache)