2012-06-15 5 views
4

В настоящее время я настроил свой спящий режим с помощью базы данных H2, используя Ehcache в качестве кэша второго уровня для запуска 2 тестов (запросить элемент 10000 раз, чтобы увидеть, как работает кеш), однако кеш не Работа. Контрольное время не изменилось по сравнению с тестом без ehcache. Статистические данные показали, что он не попал на всех, даже если кэш имеет размер = 1 (пункт был задан вопрос):Ehcache не попал при запросе одного и того же элемента.

[ name = Location cacheHits = 0 onDiskHits = 0 offHeapHits = 0 inMemoryHits = 0 misses = 0 onDiskMisses = 0 offHeapMisses = 0 inMemoryMisses = 0 size = 1 averageGetTime = 0.0 evictionCount = 0 ] 

Статистика Hibernate (. SessionFactory.getStatistics() getSecondLevelCacheStatistics ("Location")):

SecondLevelCacheStatistics[hitCount=0,missCount=0,putCount=0,elementCountInMemor‌​y=1,elementCountOnDisk=1,sizeInMemory=760] 

Вот мои конфигурации:

Maven зависимостей:

<dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-ehcache</artifactId> 
     <version>4.1.3.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>net.sf.ehcache</groupId> 
     <artifactId>ehcache-core</artifactId> 
     <version>2.5.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.1.3.Final</version> 
    </dependency> 

конфигурации Hibernate с Ehcache включена:

Configuration cfg = new Configuration() 
     .addAnnotatedClass(Location.class) 
     .setProperty("hibernate.connection.driver_class", dbConfig.getH2JdbcDriverName()) 
     .setProperty("hibernate.connection.url", dbConfig.getDbUrl()) 
     .setProperty("hibernate.connection.username", dbConfig.getUserName()) 
     .setProperty("hibernate.connection.password", dbConfig.getPassword()) 
     .setProperty("javax.persistence.validation.mode", "NONE") 
     .setProperty("hibernate.cache.use_second_level_cache", "true") 
     .setProperty("hibernate.cache.use_query_cache", "true") 
     .setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory"); 

    sessionFactory = cfg.buildSessionFactory(); 

Ehcache конфигурации XML:

<ehcache> 
<diskStore path="c:/_cached"/> 
<cache 
    name="org.hibernate.cache.StandardQueryCache" 
    maxEntriesLocalHeap="5" 
    eternal="false" 
    timeToLiveSeconds="120" 
    overflowToDisk="true"/> 

<cache 
    name="org.hibernate.cache.UpdateTimestampsCache" 
    maxEntriesLocalHeap="5000" 
    eternal="true" 
    overflowToDisk="true"/> 

<cache 
    name="Location" 
    maxElementsInMemory="10000" 
    eternal="false" 
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120" 
    overflowToDisk="true" 
    diskPersistent="false" 
    diskExpiryThreadIntervalSeconds="120" 
    memoryStoreEvictionPolicy="LRU"/> 
<defaultCache 
    maxElementsInMemory="10000" 
    eternal="false" 
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120" 
    overflowToDisk="true" 
    diskPersistent="false" 
    diskExpiryThreadIntervalSeconds="120" 
    memoryStoreEvictionPolicy="LRU"/> 
</ehcache> 

класса Database:

import org.hibernate.annotations.*; 

import javax.persistence.*; 
import javax.persistence.Entity; 
import javax.persistence.Table; 
import java.io.Serializable; 

@Entity 
@Table(name = "Location") 
@org.hibernate.annotations.Cache(region = "Location", usage = CacheConcurrencyStrategy.READ_WRITE) 
public class Location implements Serializable { 
    @Id 
    @GeneratedValue 
    @Column(name = "Id") 
    private int id; 

    @Column(name = "Name", nullable = false) 
    private String name; 

    @Column(name = "Description") 
    private String description; 

    @Column(name = "Position", nullable = false) 
    private Geometry position; 

    //getters and setters are ommited 
} 

тестовый код:

@Test 
public void testQueryCache(){ 
    int size = 10000; 
    Location lo = null; 
    long startTime = System.currentTimeMillis(); 
    Session currentSession = sessionFactory.openSession(); 
    for (int i = 0; i< size ; i++){ 
     Transaction transaction = currentSession.beginTransaction(); 
     lo = (Location) currentSession.createCriteria(Location.class) 
      .add(Restrictions.eq("id", 86)) 
      .setCacheable(true) 
      .uniqueResult(); 
     transaction.commit(); 
    } 
    long stopTime = System.currentTimeMillis(); 
    Assert.assertNotNull(lo); 
    System.out.println(String.format("\t %d ms", stopTime - startTime)); 

    Cache cache = CacheManager.getInstance().getCache("Location"); 
    System.out.println(cache.getStatistics().toString()); 

    SecondLevelCacheStatistics statistics = sessionFactory.getStatistics().getSecondLevelCacheStatistics("Location"); 
    System.out.println(statistics.toString()); 
} 

@Test 
public void testEhcacheWithGet(){ 
    int size = 10000; 
    Location lo = null; 
    long startTime = System.currentTimeMillis(); 
    for (int i = 0; i< size ; i++){ 
     Session currentSession = sessionFactory.openSession(); 
     Transaction transaction = currentSession.beginTransaction(); 
      lo = (Location) currentSession.get(Location.class, 86); 
     transaction.commit(); 
     currentSession.close(); 
    } 

    long stopTime = System.currentTimeMillis(); 
    Assert.assertNotNull(lo); 
    System.out.println(String.format("\t %d ms", stopTime - startTime)); 

    Cache cache = CacheManager.getInstance().getCache("Location"); 
    System.out.println(cache.getStatistics().toString()); 

    SecondLevelCacheStatistics statistics = sessionFactory.getStatistics().getSecondLevelCacheStatistics("Location"); 
    System.out.println(statistics.toString()); 
} 

консольных сообщений для @testQ ueryCache:

2012-06-15 15:07:03,953 DEBUG [org.jboss.logging] - Logging Provider: org.jboss.logging.Log4jLoggerProvider 
2012-06-15 15:07:04,917 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from ehcache.xml found in the classpath: file:/***PATH***/ehcache.xml 
2012-06-15 15:07:04,920 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from URL: file:/***PATH***/ehcache.xml 
2012-06-15 15:07:04,921 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from InputStream 
2012-06-15 15:07:05,085 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - Disk Store Path: c:/_cached 
2012-06-15 15:07:05,125 DEBUG [net.sf.ehcache.util.PropertyUtil] - propertiesString is null. 
2012-06-15 15:07:05,139 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheManagerEventListenerFactory class specified. Skipping... 
2012-06-15 15:07:05,186 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:07:05,186 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:07:05,188 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:07:05,190 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:07:05,191 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:07:05,191 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:07:05,191 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:07:05,192 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:07:05,192 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:07:05,192 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:07:05,193 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:07:05,193 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:07:05,222 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.UpdateTimestampsCache 
2012-06-15 15:07:05,230 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:07:05,242 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:07:05,243 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:07:05,252 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.UpdateTimestampsCache 
2012-06-15 15:07:05,252 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'org.hibernate.cache.UpdateTimestampsCache'. 
2012-06-15 15:07:05,253 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.UpdateTimestampsCache'. 
2012-06-15 15:07:05,253 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for Location 
2012-06-15 15:07:05,258 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file Location.index 
2012-06-15 15:07:05,259 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\Location.index 
2012-06-15 15:07:05,259 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file Location.index 
2012-06-15 15:07:05,260 DEBUG [net.sf.ehcache.Cache] - Initialised cache: Location 
2012-06-15 15:07:05,260 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'Location'. 
2012-06-15 15:07:05,263 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'Location'. 
2012-06-15 15:07:05,264 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.StandardQueryCache 
2012-06-15 15:07:05,265 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:07:05,266 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:07:05,267 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:07:05,268 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.StandardQueryCache 
2012-06-15 15:07:05,268 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'org.hibernate.cache.StandardQueryCache'. 
2012-06-15 15:07:05,272 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.StandardQueryCache'. 
2012-06-15 15:07:05,482 WARN [org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory] - HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults. 
2012-06-15 15:07:05,483 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.spi.UpdateTimestampsCache 
2012-06-15 15:07:05,484 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:07:05,486 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:07:05,487 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:07:05,488 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.spi.UpdateTimestampsCache 
2012-06-15 15:07:05,488 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.spi.UpdateTimestampsCache'. 
2012-06-15 15:07:05,491 WARN [org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory] - HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults. 
2012-06-15 15:07:05,492 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.internal.StandardQueryCache 
2012-06-15 15:07:05,493 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:07:05,495 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:07:05,495 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:07:05,496 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.internal.StandardQueryCache 
2012-06-15 15:07:05,497 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.internal.StandardQueryCache'. 
2012-06-15 15:07:05,772 DEBUG [net.sf.ehcache.store.disk.Segment] - put added 0 on heap 
2012-06-15 15:07:05,783 DEBUG [net.sf.ehcache.store.disk.Segment] - put added 0 on heap 
2012-06-15 15:07:05,794 DEBUG [net.sf.ehcache.store.disk.Segment] - fault removed 0 from heap 
2012-06-15 15:07:05,794 DEBUG [net.sf.ehcache.store.disk.Segment] - fault added 0 on disk 
2012-06-15 15:07:05,795 DEBUG [net.sf.ehcache.store.disk.Segment] - fault removed 0 from heap 
2012-06-15 15:07:05,795 DEBUG [net.sf.ehcache.store.disk.Segment] - fault added 0 on disk 
2012-06-15 15:07:06,190 DEBUG [net.sf.ehcache.util.UpdateChecker] - Checking for update... 
    2586 ms 
2012-06-15 15:07:08,152 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from ehcache.xml found in the classpath: file:/***PATH***/ehcache.xml 
2012-06-15 15:07:08,153 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from URL: file:/***PATH***/ehcache.xml 
2012-06-15 15:07:08,155 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from InputStream 
2012-06-15 15:07:08,159 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - Disk Store Path: c:/_cached 
[ name = Location cacheHits = 0 onDiskHits = 0 offHeapHits = 0 inMemoryHits = 0 misses = 0 onDiskMisses = 0 offHeapMisses = 0 inMemoryMisses = 0 size = 1 averageGetTime = 0.0 evictionCount = 0 ] 
2012-06-15 15:07:08,174 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Located valid 'tools.jar' at 'C:\Program Files (x86)\Java\jdk1.6.0_31\jre\..\lib\tools.jar' 
2012-06-15 15:07:08,184 INFO [net.sf.ehcache.pool.sizeof.JvmInformation] - Detected JVM data model settings of: 32-Bit HotSpot JVM 
2012-06-15 15:07:08,240 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Extracted agent jar to temporary file C:\Users\****\AppData\Local\Temp\ehcache-sizeof-agent6609755822520222855.jar 
2012-06-15 15:07:08,241 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Trying to load agent @ C:\Users\****\AppData\Local\Temp\ehcache-sizeof-agent6609755822520222855.jar 
2012-06-15 15:07:08,247 INFO [net.sf.ehcache.pool.impl.DefaultSizeOfEngine] - using Agent sizeof engine 
SecondLevelCacheStatistics[hitCount=0,missCount=0,putCount=0,elementCountInMemory=1,elementCountOnDisk=1,sizeInMemory=760] 

Консольные Сообщения @testEhcacheWithGet:

2012-06-15 15:09:26,046 DEBUG [org.jboss.logging] - Logging Provider: org.jboss.logging.Log4jLoggerProvider 
2012-06-15 15:09:26,993 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from ehcache.xml found in the classpath: file:/***PATH***/ehcache.xml 
2012-06-15 15:09:26,995 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from URL: file:/***PATH***/ehcache.xml 
2012-06-15 15:09:26,997 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from InputStream 
2012-06-15 15:09:27,156 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - Disk Store Path: c:/_cached 
2012-06-15 15:09:27,188 DEBUG [net.sf.ehcache.util.PropertyUtil] - propertiesString is null. 
2012-06-15 15:09:27,200 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheManagerEventListenerFactory class specified. Skipping... 
2012-06-15 15:09:27,247 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:09:27,248 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:09:27,249 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:09:27,251 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:09:27,252 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:09:27,252 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:09:27,252 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:09:27,252 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:09:27,256 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:09:27,257 DEBUG [net.sf.ehcache.Cache] - No BootstrapCacheLoaderFactory class specified. Skipping... 
2012-06-15 15:09:27,257 DEBUG [net.sf.ehcache.Cache] - CacheWriter factory not configured. Skipping... 
2012-06-15 15:09:27,257 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - No CacheExceptionHandlerFactory class specified. Skipping... 
2012-06-15 15:09:27,285 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.StandardQueryCache 
2012-06-15 15:09:27,292 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:09:27,304 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:09:27,305 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.StandardQueryCache.index 
2012-06-15 15:09:27,314 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.StandardQueryCache 
2012-06-15 15:09:27,314 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'org.hibernate.cache.StandardQueryCache'. 
2012-06-15 15:09:27,314 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.StandardQueryCache'. 
2012-06-15 15:09:27,316 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for Location 
2012-06-15 15:09:27,318 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file Location.index 
2012-06-15 15:09:27,319 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\Location.index 
2012-06-15 15:09:27,319 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file Location.index 
2012-06-15 15:09:27,320 DEBUG [net.sf.ehcache.Cache] - Initialised cache: Location 
2012-06-15 15:09:27,320 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'Location'. 
2012-06-15 15:09:27,323 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'Location'. 
2012-06-15 15:09:27,324 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.UpdateTimestampsCache 
2012-06-15 15:09:27,325 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:09:27,326 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:09:27,327 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.UpdateTimestampsCache.index 
2012-06-15 15:09:27,328 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.UpdateTimestampsCache 
2012-06-15 15:09:27,328 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured. Skipping for 'org.hibernate.cache.UpdateTimestampsCache'. 
2012-06-15 15:09:27,328 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.UpdateTimestampsCache'. 
2012-06-15 15:09:27,530 WARN [org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory] - HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults. 
2012-06-15 15:09:27,531 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.spi.UpdateTimestampsCache 
2012-06-15 15:09:27,533 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:09:27,534 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:09:27,534 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.spi.UpdateTimestampsCache.index 
2012-06-15 15:09:27,538 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.spi.UpdateTimestampsCache 
2012-06-15 15:09:27,539 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.spi.UpdateTimestampsCache'. 
2012-06-15 15:09:27,544 WARN [org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory] - HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults. 
2012-06-15 15:09:27,545 DEBUG [net.sf.ehcache.store.MemoryStore] - Initialized net.sf.ehcache.store.MemoryStore for org.hibernate.cache.internal.StandardQueryCache 
2012-06-15 15:09:27,546 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:09:27,548 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Matching data file missing (or empty) for index file. Deleting index file c:\_cached\org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:09:27,548 DEBUG [net.sf.ehcache.store.disk.DiskStorageFactory] - Failed to delete file org.hibernate.cache.internal.StandardQueryCache.index 
2012-06-15 15:09:27,549 DEBUG [net.sf.ehcache.Cache] - Initialised cache: org.hibernate.cache.internal.StandardQueryCache 
2012-06-15 15:09:27,549 DEBUG [net.sf.ehcache.config.ConfigurationHelper] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'org.hibernate.cache.internal.StandardQueryCache'. 
2012-06-15 15:09:27,835 DEBUG [net.sf.ehcache.store.disk.Segment] - put added 0 on heap 
2012-06-15 15:09:27,869 DEBUG [net.sf.ehcache.store.disk.Segment] - fault removed 0 from heap 
2012-06-15 15:09:27,870 DEBUG [net.sf.ehcache.store.disk.Segment] - fault added 0 on disk 
2012-06-15 15:09:28,251 DEBUG [net.sf.ehcache.util.UpdateChecker] - Checking for update... 
    4283 ms 
2012-06-15 15:09:31,910 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from ehcache.xml found in the classpath: file:/***PATH***/ehcache.xml 
2012-06-15 15:09:31,911 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from URL: file:/***PATH***/ehcache.xml 
2012-06-15 15:09:31,912 DEBUG [net.sf.ehcache.config.ConfigurationFactory] - Configuring ehcache from InputStream 
2012-06-15 15:09:31,915 DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - Disk Store Path: c:/_cached 
[ name = Location cacheHits = 0 onDiskHits = 0 offHeapHits = 0 inMemoryHits = 0 misses = 0 onDiskMisses = 0 offHeapMisses = 0 inMemoryMisses = 0 size = 1 averageGetTime = 0.0 evictionCount = 0 ] 
2012-06-15 15:09:31,932 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Located valid 'tools.jar' at 'C:\Program Files (x86)\Java\jdk1.6.0_31\jre\..\lib\tools.jar' 
2012-06-15 15:09:31,942 INFO [net.sf.ehcache.pool.sizeof.JvmInformation] - Detected JVM data model settings of: 32-Bit HotSpot JVM 
2012-06-15 15:09:32,001 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Extracted agent jar to temporary file C:\Users\****\AppData\Local\Temp\ehcache-sizeof-agent6451434728035591561.jar 
2012-06-15 15:09:32,002 INFO [net.sf.ehcache.pool.sizeof.AgentLoader] - Trying to load agent @ C:\Users\****\AppData\Local\Temp\ehcache-sizeof-agent6451434728035591561.jar 
2012-06-15 15:09:32,009 INFO [net.sf.ehcache.pool.impl.DefaultSizeOfEngine] - using Agent sizeof engine 
SecondLevelCacheStatistics[hitCount=0,missCount=0,putCount=0,elementCountInMemory=1,elementCountOnDisk=1,sizeInMemory=760] 

Пожалуйста, помогите мне понять, что я делаю не так !!! :(

Спасибо большое !!!

+0

Есть некоторые предупреждения о том, что файлы кэша не присутствуют или недоступны. Правильны ли файловые системы? – Thilo

+0

Да, пути к файловой системе верны. – Zun

ответ

0

только быстро просматривать через это, но вы настроить для использования в спящий режим, чтобы использовать net.sf.ehcache.hibernate.EhCacheRegionFactory, а не singleton, а затем использовать CacheManager.getInstance() ... Пробовали ли вы монитор ? активность кэша через статистику Hibernate Wonder ли вы на самом деле использовать тот же CacheManage как и Hibernate ...

+0

Спасибо, но я получил эту статистику, когда я использовал статистику Hibernate: SecondLevelCacheStatistics [HitCount = 0, missCount = 0, putCount = 0, elementCountInMemory = 1, elementCountOnDisk = 1, sizeInMemory = 760] Cache был не попал вообще. Есть ли у вас какие-нибудь идеи? – Zun

0

вы пробовали:

sessionFactory.getCurrentSession().get(Location.class, 86); 

вместо Усин g Критерии запроса? Насколько я понимаю, Hibernate только попадает в кеш второго уровня с загрузкой объекта с помощью @Id, поэтому используя get/load в сеансе.

Если вы делаете критерии Cacheable:

sessionFactory.getCurrentSession.createCriteria().setCacheable(true).uniqueResult(); 

и включить сущности и запросы кэша Вы поразите кэш второго уровня, когда вы выполнить этот запрос.

+0

Я попробовал оба ваших предложения, однако кеш все еще не попал. Я обновил свои вопросы. Есть ли у вас какие-нибудь идеи? – Zun

+0

Почему у вас есть переменная, называемая sessionFactory, а затем, когда вы проверяете статистику, вы делаете dbAccess.getSessionFactory()? Что такое dbAccess? –

+0

Почему не просто sessionFactory.getStatistics(). GetSecondLevelCacheStatistics ("Location"); –

2

Поздний ответ, но

Попробуйте добавить statistics="true" в <cache> элемент, который вы хотите отслеживать. Также добавьте <property name="hibernate.generate_statistics">true</property> в hibernate.cfg.xml

Смежные вопросы