【发布时间】:2014-02-09 03:14:42
【问题描述】:
很抱歉,这篇文章很长,但我想在我的帖子中准确无误。
我有一个 spring mvc 3.1 Web 应用程序,并且刚刚在我的 Web 应用程序中构建了 ehcache,我用它来缓存从数据库构建的所有值列表(下拉列表)。
这是我的设置示例...
<!-- Cache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.0</version>
</dependency>
...
<ehcache>
<diskStore path="java.io.tmpdir"/>
<cache
name="lovStore"
maxElementsInMemory="512"
eternal="false"
timeToIdleSeconds="60"
timeToLiveSeconds="60"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
...
<cache:annotation-driven />
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref="ehcache"/>
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="classpath:ehcache.xml"/>
...
@Cacheable(value = "lovStore", key = "#code")
public Map<String, String> getLov(String code) throws ReportingManagerException {
return MockLOVHelper.getInstance().getLov(code);
}
网上很多教程都在讨论使用@cacheEvict 方法驱逐缓存,但这不适合我。我认为我更适合使用 timeToLiveSeconds 选项来驱逐缓存。
当我查看日志时,缓存肯定在工作,但缓存的驱逐却没有。我在网上阅读了其他一些关于 timeToLiveSeconds 如何不真正驱逐缓存的文章,但其他类似 http://code.google.com/p/ehcache-spring-annotations/wiki/EvictExpiredElements 的文章说,您必须创建特殊设置才能驱逐缓存。
有人可以帮助我了解我的缓存是否应该被驱逐,以及我如何驱逐,因为文章中提到的内容我无法理解如何实现。
这是我的日志的样子。但是没有被驱逐的迹象……
2014-01-20 13:32:41,791 DEBUG [AnnotationCacheOperationSource] - Adding cacheable method 'getLov' with attribute: [CacheableOperation[public java.util.Map com.myer.reporting.dao.mock.MockLovStoreDaoImpl.getLov(java.lang.String) throws com.myer.reporting.exception.ReportingManagerException] caches=[lovStore] | condition='' | key='#code']
谢谢
【问题讨论】:
标签: spring spring-mvc ehcache