У меня проблема, когда net.sf.ehcache.CacheManager
появляется, возвращает недопустимую статистику.
Я использую ehcache-core v2.3.2
(последняя версия) с ehcache-spring-annotations
.
Проблема заключается в том, что getMemoryStoreObjectCount
возвращает 1 объект, в то время как getCacheHits
и getCacheMisses
возвращает 0. Разве общий счет не должен быть hits + misses
?
Ниже приведен пример unit test, который должен отображаться в пустой базе данных:
@Test
public void testCache() {
Entity e = ..
dao.storeEntity(e);
dao.getEntity(e);
assertEquals(1, cache.getStatistics().getMemoryStoreObjectCount()); // ok
assertEquals(0, cache.getStatistics().getCacheHits()); // ok
assertEquals(1, cache.getStatistics().getCacheMisses()); // fails due to 0
}
Для полноты я включаю всю необходимую конфигурацию:
Spring config
<ehcache:annotation-driven cache-manager="ehCacheManager" />
<bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
ehcache.xml
<ehcache>
<defaultCache eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU"/>
</ehcache>
дао
@Cacheable([email protected](name="StringCacheKeyGenerator"))
public Entity getEntity(Serializable key) {
return // sql ...
}