日期:2014-05-17  浏览次数:24313 次

使用spring管理缓存的问题
我在项目中用springmodules来管理缓存,缓存使用的是oscache,我把结果集进行了缓存,缓存结果集是一个list,在对list里的一条数据做了修改,就要通知oscache刷新缓存,这个刷新是重新从数据库查,问题是我只改变一条数据,就要改变刷新掉整个list,所以能不能修改数据成功后,不用刷新缓存,直接将缓存中的数据就行修改。
spring具体配置文件如下:
XML code
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd ">

    <bean id="cacheManager" class="org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:oscache.properties" />                            
    </bean>
    
    <bean id="oscacheFacade" class="org.springmodules.cache.provider.oscache.OsCacheFacade">
        <property name="cacheManager" ref="cacheManager" />
    </bean>
    
    <bean id="cachingInterceptor001" class="org.springmodules.cache.interceptor.caching.MethodMapCachingInterceptor">  
        <property name="cacheProviderFacade" ref="oscacheFacade"/>  
        <property name="cachingModels">  
            <props>  
                <prop key="com.qh.dao.StudentDao.selectStudent">groups=aa</prop>
            </props>  
        </property>  
      </bean>  
      
      <bean id="flushInterceptor001" class="org.springmodules.cache.interceptor.flush.MethodMapFlushingInterceptor">
          <property name="cacheProviderFacade" ref="oscacheFacade"/>  
          <property name="flushingModels">
            <props>
                <prop key="com.qh.dao.StudentDao.updateStudentById">groups=aa</prop>
            </props>
        </property>
          
      </bean>
      
      <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
            <property name="beanNames">  
            <value>*Dao</value>  
        </property>  
        <property name="interceptorNames">  
            <list>  
                <value>cachingInterceptor001</value>  
                <value>flushInterceptor001</value>
            </list>  
        </property>  
      </bean>  

</beans>


------解决方案--------------------
关注,围观..凑凑字数.太恶心人了