【发布时间】:2013-08-02 19:11:06
【问题描述】:
我有一个包含多种方法的服务,并尝试使用 Spring @Cacheable 注释来缓存它们。一切正常,除了我发现以数组作为方法参数的方法没有被缓存。考虑到数组可以保存不同的值,这在某种程度上是有道理的,但我仍然认为这是可能的。
以下方法被缓存:
@Cacheable("myCache")
public Collection<Building> findBuildingByCode(String buildingCode) {...}
@Cacheable("myCache")
public Collection<Building> getBuildings() {...}
但是,如果我将findBuildingByCode 方法更改为以下任一方法,它不会被缓存:
@Cacheable("myCache")
public Collection<Building> findBuildingByCode(String[] buildingCode) {...}
@Cacheable("myCache")
public Collection<Building> findBuildingByCode(String... buildingCode) {...}
这里是相关的Spring xml配置:
<!-- Cache beans -->
<cache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref="ehcache" />
<!-- EhCache library setup -->
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
Ehcache配置:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<diskStore path="java.io.tmpdir/ehcache" />
<!-- Default settings -->
<defaultCache eternal="false" maxElementsInMemory="1"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="100" memoryStoreEvictionPolicy="LRU" />
<!-- Other caches -->
<cache name="myCache" eternal="false" maxElementsInMemory="500"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="43200" memoryStoreEvictionPolicy="LRU" />
</ehcache>
这是已知功能还是错误?
【问题讨论】:
标签: java spring ehcache spring-annotations