Comment dois-je utiliser @CachePut et @CacheEvict annotations avec ehCache (ehCache 2.4.4, Printemps 3.1.1)

J'ai essayé quelques nouvelles du Printemps fonctionnalités et j'ai trouvé que @CachePut et @CacheEvict annotations n'a aucun effet. Peut-être que je fais quelque chose de mal. Pourriez-vous m'aider?

Mon applicationContext.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"/>

Cette partie fonctionne bien.

@Cacheable(value = "finders")
public Finder getFinder(String code)
{
    return getFinderFromDB(code);
}

@CacheEvict(value = "finders", allEntries = true)
public void clearCache()
{
}

Mais si je veux supprimer la valeur unique de cache ou de la remplacer, je ne peux pas faire. Ce que j'ai testé:

@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;
}

OriginalL'auteur Gosha U. | 2012-02-29