मुझे कोई समस्या है जहां net.sf.ehcache.CacheManager
अमान्य आंकड़े लौटाता है।गलत ehcache आंकड़े: हिट + मिस == 0
मैं ehcache-core v2.3.2
(नवीनतम संस्करण) ehcache-spring-annotations
के साथ उपयोग कर रहा हूं।
समस्या है कि getMemoryStoreObjectCount
रिटर्न वस्तु जबकि दोनों getCacheHits
और getCacheMisses
रिटर्न । कुल गणना hits + misses
होने की संख्या नहीं है?
नीचे इकाई परीक्षण समस्या उदाहरण देकर स्पष्ट करना चाहिए (यह एक खाली डेटाबेस पर लागू की गई):
स्प्रिंग config
:@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
}
पूर्णता के लिए मैं सभी आवश्यक विन्यास शामिल
<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 ...
}
हाय, क्या आप अपने कोड को स्प्रिंग कॉन्फ़िगरेशन से अपने जुनीट परीक्षण में "कैश" चर कैसे प्राप्त करते हैं, इस बारे में पोस्ट करना चाहते हैं? – Dave