Próbowałem nowych funkcji Spring i odkryłem, że adnotacje @CachePut i @CacheEvict nie mają żadnego efektu. Może być coś złego. Czy mógłbyś mi pomóc?Jak używać adnotacji @CachePut i @CacheEvict przy użyciu ehCache (ehCache 2.4.4, Spring 3.1.1)
Moja aplikacjaContext.xml.
<cache:annotation-driven />
<!--also tried this-->
<!--<ehcache:annotation-driven />-->
<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"/>
Ta część działa dobrze.
@Cacheable(value = "finders")
public Finder getFinder(String code)
{
return getFinderFromDB(code);
}
@CacheEvict(value = "finders", allEntries = true)
public void clearCache()
{
}
Ale jeśli chcę usunąć pojedynczą wartość z pamięci podręcznej lub nadpisać ją, nie mogę tego zrobić. Co przetestowałem:
@CacheEvict(value = "finders", key = "#finder.code")
public boolean updateFinder(Finder finder, boolean nullValuesAllowed)
{
// ...
}
/////////////
@CacheEvict(value = "finders")
public void clearCache(String code)
{
}
/////////////
@CachePut(value = "finders", key = "#finder.code")
public Finder updateFinder(Finder finder, boolean nullValuesAllowed)
{
// gets newFinder that is different
return newFinder;
}
miał ten sam problem i to naprawił. Dzięki! Ale jaki jest konkretny problem związany z "@CachePut" i "@Cachable" w tej samej klasie? – DOUBL3P