当前位置: 代码迷 >> Java Web开发 >> Spring + ehcache 的疑义
  详细解决方案

Spring + ehcache 的疑义

热度:341   发布时间:2016-04-16 22:16:42.0
Spring + ehcache 的疑问
public static void main(String[] args) {
PropertyConfigurator configure = new PropertyConfigurator();
configure.doConfigure("config/Springlog4j.properties",org.apache.log4j.LogManager.getLoggerRepository());
BeanFactory factory = new ClassPathXmlApplicationContext("ehcache/property/application-ecache.xml");

                System.out.println("start");
@SuppressWarnings("unused")
ehcacheService cacheBean = (ehcacheService) factory.getBean("ehcacheService");
List<String> user1= cacheBean.getUsers();
 for(String e : user1){
 System.out.println(e);
 }
 cacheBean.addUser("ffff");
 List<String> user2= cacheBean.getUsers();
 for(String e : user2){
 System.out.println(e);     // 疑问:这个位置不应该读取缓存的ABCD吗?为什么ffff也抽出来了??
 }
System.out.println("end");
}
-----------XML
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
   <property name="configLocation"  value="classpath:ehcache/property/ehcache.xml"/>
</bean>

<bean id="cacheProviderFacade" class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
<property name="cacheManager" ref="cacheManager"/>
</bean>

<bean id="cachingInterceptor" class="org.springmodules.cache.interceptor.caching.MethodMapCachingInterceptor">
<property name="cacheProviderFacade" ref="cacheProviderFacade"/>
<property name="cachingListeners">
<null/>
</property>
<property name="cachingModels">
<props>
<prop key="ehcache.ehcacheService.getUsers">cacheName=testCache</prop>
</props>
</property>
</bean>

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<idref bean="ehcacheService" />
</list>
</property>
<property name="interceptorNames">
<list>
<value>cachingInterceptor</value>
</list>
</property>
</bean>

    <bean id="ehcacheService" class="ehcache.ehcacheManager">
        <property name="name">
            <list>
                <value>A</value>
                <value>B</value>
                <value>C</value>
                <value>D</value>
            </list>
        </property>
    </bean>
------解决方案--------------------
确定是 读的缓存吗
------解决方案--------------------
ehcacheService里面有缓存设置吗,我看好像用的是自动代理缓存
  相关解决方案