1

Is there a way of indicating to expire/evict the cache object based on a property of the POJO cached.

In below code, it caches Foo instance. Foo class has a expiresIn property class Foo { Date expiresIn; }

I want to hint to spring to expire the cache based on the value of expiresIn property of cached element. Is this feasible?

@Cacheable("my-cache-key")
    Foo getCachedToken(String userName, String password) throws AuthException

My Cache.xml is below:

<cache:annotation-driven/>

<bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
    <property name="cacheManagers">
        <list>
            <ref bean="mapCacheManager"/>
        </list>
    </property>
</bean>

<bean id="mapCacheManager" class="org.springframework.cache.concurrent.ConcurrentMapCacheManager">
    <property name="cacheNames">
        <list>
            <value>my-cache-key</value>
        </list>
    </property>
</bean>
4

1 回答 1

0

我猜你错过了部分名称如何设置 TTL/TTI/Eviction 策略/XXX 功能?从参考指南。

这是一个缓存基础设施抽象;它不是缓存提供程序。ConcurrentMapCacheManager是我们为测试目的或超简单用例提供的一个非常简单的实现。如果您需要驱逐策略,请选择支持该策略的缓存库。想到 Ehcache、番石榴或 Hazelcast。它们都有一个CacheManager实现。

于 2015-03-17T15:17:55.100 回答