如何知道Hibernate已经成功运用了二级缓存EhCache

来源:互联网 发布:网络安全检查报告 编辑:程序博客网 时间:2024/06/11 20:46

http://yulimin.javaeye.com/blog/30826

问题是DEBUG之后我也不清楚应该看哪里!
DEBUG的信息实在是太多,很难看全!
能否给个实例,指出那里显示了使用了二级缓存!

 

对Log4J进行分类分级一下,我的如下,你可以进行修改:

代码
  1. log4j.threshold = ALL   
  2. log4j.rootLogger = ALL   
  3. #   
  4. log4j.category.org.springframework debug,FrameWorkSpring   
  5. log4j.category.org.hibernate debug,FrameWorkHibernate   
  6. log4j.category.net.sf.ehcache debug,FrameWorkEhCache   
  7.   
  8. log4j.appender.FrameWorkSpring org.apache.log4j.DailyRollingFileAppender   
  9. log4j.appender.FrameWorkSpring.File ${system.logPath}/FrameWorkSpring.log   
  10. log4j.appender.FrameWorkSpring.DatePattern yyyy-MM-dd'.log'   
  11. log4j.appender.FrameWorkSpring.layout org.apache.log4j.PatternLayout   
  12. log4j.appender.FrameWorkSpring.layout.ConversionPattern [%c]-[%p] %m%n   
  13. log4j.appender.FrameWorkSpring.append false  
  14.   
  15. log4j.appender.FrameWorkHibernate org.apache.log4j.DailyRollingFileAppender   
  16. log4j.appender.FrameWorkHibernate.File ${system.logPath}/FrameWorkHibernate.log   
  17. log4j.appender.FrameWorkHibernate.DatePattern yyyy-MM-dd'.log'   
  18. log4j.appender.FrameWorkHibernate.layout org.apache.log4j.PatternLayout   
  19. log4j.appender.FrameWorkHibernate.layout.ConversionPattern [%c]-[%p] %m%n   
  20. log4j.appender.FrameWorkHibernate.append false  
  21.   
  22. log4j.appender.FrameWorkEhCache org.apache.log4j.DailyRollingFileAppender   
  23. log4j.appender.FrameWorkEhCache.File ${system.logPath}/FrameWorkEhCache.log   
  24. log4j.appender.FrameWorkEhCache.DatePattern yyyy-MM-dd'.log'   
  25. log4j.appender.FrameWorkEhCache.layout org.apache.log4j.PatternLayout   
  26. log4j.appender.FrameWorkEhCache.layout.ConversionPattern [%c]-[%p] %m%n   
  27. log4j.appender.FrameWorkEhCache.append false  

 

可以看到命中的信息

代码
  1. [net.sf.ehcache.store.MemoryStore]-[DEBUG] xxx.xxx.XyzCache: xxx.xxx.XyzMemoryStore hit for xxx.xxx.Xyz#8  

 

没命中的信息:

代码
  1. [net.sf.ehcache.Cache]-[DEBUG] xxx.xxx.Xyz cache - Miss   


大概是这样子的,可以继续进行观察它的详细log信息再做分析。 

增加一些信息:

EhCache初始化的信息

代码
  1. [net.sf.ehcache.CacheManager]-[DEBUG] Configuring ehcache from classpath.   
  2. [net.sf.ehcache.config.ConfigurationFactory]-[DEBUG] Configuring ehcache from ehcache.xml found in the classpath: file:xxx/WEB-INF/classes/ehcache.xml   
  3. [net.sf.ehcache.config.ConfigurationFactory]-[DEBUG] Configuring ehcache from URL: file:xxx/WEB-INF/classes/ehcache.xml   
  4. [net.sf.ehcache.config.ConfigurationFactory]-[DEBUG] Configuring ehcache from InputStream   
  5. [net.sf.ehcache.config.DiskStoreConfiguration]-[DEBUG] Disk Store Path: xxx   
  6. [net.sf.ehcache.config.ConfigurationHelper]-[DEBUG] No CacheManagerEventListenerFactory class specified. Skipping...   
  7. [net.sf.ehcache.config.ConfigurationHelper]-[DEBUG] No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.   
  8. [net.sf.ehcache.config.ConfigurationHelper]-[DEBUG] No BootstrapCacheLoaderFactory class specified. Skipping...   

 

EhCache开始工作的信息

代码
  1. [net.sf.ehcache.store.DiskStore]-[DEBUG] Deleting data file xxx.xxx.Xyz.data   
  2. [net.sf.ehcache.store.MemoryStore]-[DEBUG] Initialized net.sf.ehcache.store.LruMemoryStore for xxx.xxx.Xyz   
  3. [net.sf.ehcache.store.LruMemoryStore]-[DEBUG] xxx.xxx.Xyz Cache: Using SpoolingLinkedHashMap implementation   
  4. [net.sf.ehcache.Cache]-[DEBUG] Initialised cache: xxx.xxx.Xyz