[英]Logging Ehcache get requests
I am trying to write a class that would trace all Ehcache GET requests. 我正在尝试编写一个将跟踪所有Ehcache GET请求的类。 For the performance obsessed - this would only be switched on for debugging purposes.
出于对性能的痴迷-仅出于调试目的而将其打开。
I can see following three options available: 我可以看到以下三个选项:
1) write an implementation of net.sf.ehcache.event.CacheEventListener
. 1)编写
net.sf.ehcache.event.CacheEventListener
的实现。 This would be my preferred way, but it only has PUT/REMOVE/etc. 这将是我的首选方式,但是只有PUT / REMOVE / etc。 hooks.
钩子。 No GET.
没有得到。 Doh!
h!
2) write an implementation of net.sf.ehcache.statistics.CacheUsageListener
. 2)编写
net.sf.ehcache.statistics.CacheUsageListener
的实现。 The problem with this approach is that this interface is more designed for statistics and does not even provide access to things like current cache key/element, so I would have to do horrible hacks (think: sharing state through ThreadLocal
) to achieve what I want. 这种方法的问题在于,该接口是为统计数据而设计的,甚至不提供对当前缓存键/元素之类的访问,因此我将不得不进行骇人的攻击(想想:通过
ThreadLocal
共享状态)来实现我想要的功能。 Yuck! !
3) write an Ehcache wrapper, and channel all requests through it. 3)编写一个Ehcache包装器,并通过它包装所有请求。 Quite painful as we use Ehcache in different ways (with Hibernate and without), meaning I would have to write different wrappers for all these different cases.
当我们以不同的方式(使用Hibernate和不使用Ehcache)使用Ehcache时,这非常痛苦,这意味着我将不得不针对所有这些不同的情况编写不同的包装器。 Adds maintenance pains and isn't really precise as it is not possible to know, for example, if a GET operation has hit a stale entry or not.
这增加了维护工作的负担,而且并不是很精确,因为无法知道例如GET操作是否已过期。
Are there any other options I missed? 我还有其他选择吗?
A fourth option would be to enable debug level logging for net.sf.ehcache.Cache and enable cache statistics for the caches you want to trace the information. 第四个选择是启用调试级别日志记录net.sf.ehcache.Cache 并启用要跟踪的信息的缓存缓存的统计信息。 You'd then get "Cache: " + getName() + " store hit for " + key" or "configuration.getName() + " cache hit, but element expired"" log statements... So for misses as well.
然后,您将获得“高速缓存:” +“ getName()” +“存储命中“ +键”或“ configuration.getName()+“高速缓存命中,但元素已过期”的日志语句...因此也适用于未命中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.