【发布时间】:2017-07-14 02:12:45
【问题描述】:
我正在尝试将 Ehcache 与我的 Java Spring MVC Web 应用程序集成。我已按照以下文章中的说明进行操作:
https://dzone.com/articles/implementing-ehcache-using。
我在pom.xml 文件中添加了以下依赖项:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.0</version>
</dependency>
我的ehcache.xml如下:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir" />
<cache name="swcmRestData"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="1000"
eternal="false"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>
我的root-context.xml 中有以下条目:
<!-- EhCache Configuration -->
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" p:shared="true"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache"/>
我有一个方法要启用 ehCache:
@Cacheable(value="swcmRestData", key="url")
public <T> T getEntity(String url, java.lang.Class<T> gt) throws RestException
{
T t = restClientService.getEntity(url, gt);
return t;
}
如果将相同的 url 传递给指定的方法,我希望从 ehCache 中检索数据。运行代码时我没有收到任何错误。但看起来缓存不起作用。这里有什么我想念的吗
【问题讨论】:
-
我猜断点会帮助你。如果它是从缓存中获取的,这个方法将不会被执行。
-
如果这是一种方式,那么我的缓存不起作用。我不确定出了什么问题
标签: java spring-mvc ehcache