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>