Tengo un problema donde aparece net.sf.ehcache.CacheManager
y devuelve estadísticas no válidas.Estadísticas incorrectas de ehcache: hits + misses == 0
Estoy usando ehcache-core v2.3.2
(última versión) con ehcache-spring-annotations
.
El problema es quegetMemoryStoreObjectCount
rendimientos objeto mientras que ambos getCacheHits
y getCacheMisses
rendimientos . ¿No se supone que el conteo total es hits + misses
?
debajo de la prueba unitaria debería ilustrar el problema (que se aplica a una base de datos vacía):
@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
}
Para completar I incluyen toda la configuración esencial:
config primavera
<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>
DAO
@Cacheable([email protected](name="StringCacheKeyGenerator"))
public Entity getEntity(Serializable key) {
return // sql ...
}
Hola, ¿te importaría publicar tu código sobre cómo obtuviste la variable "caché" en tu prueba JUnit de la configuración de Spring? – Dave