我在独立环境中使用Spring3.1。
我正在使用@Cacheable注释缓存我的条目。
有时,我需要迭代缓存列表以获取特定值(不是键)。 因此,我设法检索缓存列表,但如何迭代其元素?
有时,我需要迭代缓存列表以获取特定值(不是键)。 因此,我设法检索缓存列表,但如何迭代其元素?
private ClientDTO getClientDTOByClientId(Integer clientId)
{
Cache clientCache = null;
try
{
clientCache = ehCacheCacheManager.getCache("client");
//need here to iterate on clientCache. how?
}
catch (Exception e)
{
log.error("Couldnt retrieve client from cache. clientId=" + clientId);
}
return clientDTO;
}
我正在使用ehcache机制。
<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" />
感谢你,雷。
.getNativeCache()
以获取底层缓存管理器实现。 - Matt Brock