Как мне использовать аннотации @CachePut и @CacheEvict с ehCache (ehCache 2.4.4, Spring 3.1.1)

Я попробовал некоторые новые возможности Spring и обнаружил, что аннотации @CachePut и @CacheEvict не действуют. Может я что-то не так делаю. Не могли бы вы мне помочь?

Мой 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"/>

Эта часть работает хорошо.

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

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

Но если я хочу удалить одно значение из кеша или переопределить его, я не могу этого сделать. Что я тестировал:

@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;
}
13
задан Gosha U. 29 February 2012 в 14:06
поделиться