简体   繁体   English

是否有免费的 Java 缓存库可以提供统计信息并在重启时保留状态?

[英]Is there a free Java caching library that provides statistics and preserves state on restart?

[Edited] I am re-re-writing my question, hoping to be this time following the rules good questions and asking about a "narrowed enough" topic. [已编辑] 我正在重新编写我的问题,希望这次能够遵循规则好问题并询问“足够狭窄”的话题。 I keep the information I initially provided, in case any reader is interested in details.我保留了我最初提供的信息,以防任何读者对细节感兴趣。


My question:我的问题:

I have been investigating free Java caching libraries and I found that all of them provide more or less the same features.我一直在研究免费的 Java 缓存库,我发现它们都提供或多或少相同的功能。 But there are 2 tools that stand out over the rest, because they provide a distinctive feature:但是有 2 个工具比其他工具脱颖而出,因为它们提供了一个独特的功能:

  • EHCache: Provides statistics for the cached elements. EHCache:提供缓存元素的统计信息。 At any point you can get the metadata of each element, having access to details, such as the hit count - the number of times the entry was requested while it was in the cache.在任何时候,您都可以获得每个元素的元数据,可以访问详细信息,例如命中计数 - 条目在缓存中时被请求的次数。
  • Infinispan: Provides a persistence-based mechanism to preserve cached data. Infinispan:提供基于持久性的机制来保存缓存数据。 This allows applications to not lose the cached elements on restart.这允许应用程序在重新启动时不会丢失缓存的元素。 Several persistence methods are supported, like database and filesystem.支持多种持久性方法,如数据库和文件系统。

I am wondering if there is another library that combines these 2 great features.我想知道是否有另一个库结合了这两个强大的功能。 Does anyone know about one?有人知道一个吗?

Thank you.谢谢你。


My original post:我的原帖:

I am working on a component that provides access to a reporting layer .我正在研究一个提供对报告层的访问的组件。 Reports are generated on demand , but when a given report has been run the result (a Java object) can be cached and served again later if the same report is requested, without going again to the reporting engine.报告是按需生成的,但是当给定的报告已经运行时,如果请求相同的报告,结果(Java 对象)可以被缓存并在以后再次提供,而无需再次进入报告引擎。

I need to limit to " X " (configurable) the number of cached items.我需要将缓存项目的数量限制为“ X ”(可配置)。 When the cache size has reached " X " elements and a new (not cached) report is requested I need to remove the " least-frequently-used " entry (LFU).当缓存大小达到“ X ”元素并且请求新的(未缓存的)报告时,我需要删除“最不常用”条目(LFU)。

My component is notified when the reporting data changes in the data warehouse.当数据仓库中的报告数据发生变化时,我的组件会收到通知。 In that case I need to:在这种情况下,我需要:

  • Figure out which ones are the " Y " " most-frequently-used " reports (being Y < X ).找出哪些是“ Y ”“最常用”的报告(即Y < X )。
  • Invalidate the cache.使缓存无效。
  • Re-generate those reports through the reporting engine.通过报告引擎重新生成这些报告。
  • Re-cache them.重新缓存它们。

These are all operations typically provided by most of the caching tools/libraries.这些是大多数缓存工具/库通常提供的所有操作。

An additional requirement for me is that the cached reports must survive JVM restarts .对我的另一个要求是缓存的报告必须在 JVM 重新启动后继续存在 This is, I cannot lose the information of which ones were the cached entries and I cannot re-generate them every time my application is restarted - because it would be too much load on the reporting engine.也就是说,我不能丢失哪些是缓存条目的信息,并且每次我的应用程序重新启动时我都无法重新生成它们 - 因为它会给报告引擎带来太多负载。

My problem: I cannot find a free library that covers all my needs.我的问题:找不到可以满足我所有需求的免费图书馆。 In summary, these would be the required features:总之,这些将是所需的功能:

  • Free / commercial-friendly license.免费/商业友好的许可证。
  • Persistent storage, saving state on JVM/server restart/crash.持久存储,在 JVM/服务器重启/崩溃时保存状态。
  • Java API, providing element statistics. Java API,提供元素统计。 I need to be able to "select the top X elements in cache" - using the eviction algorithm ranking as ordering.我需要能够“选择缓存中的前 X 个元素” - 使用驱逐算法排名作为排序。
  • Easy to integrate with an application running on Tomcat.易于与在 Tomcat 上运行的应用程序集成。

The closest option I found is EHCache.我找到的最接近的选项是 EHCache。 It exposes the hit count for each element - but not the "real" ranking used by the eviction algorithm.它公开了每个元素的命中计数 - 但不是驱逐算法使用的“真实”排名。 Besides, persistent restartable mechanism is available only for a non-free version - BigMemory, from Terracotta.此外,持久可重启机制仅适用于非免费版本 - 来自 Terracotta 的 BigMemory。

Other alternative I have seen is Infinispan, but it does not expose entry-level statistics - only cache-level statistics - and requires JMX.我见过的其他替代方法是 Infinispan,但它不公开入门级统计信息——仅公开缓存级统计信息——并且需要 JMX。

It sounds like what you are trying to do is create a document store that has functionality found in some caching frameworks, but itself isn't really a cache.听起来您想要做的是创建一个文档存储,它具有某些缓存框架中的功能,但它本身并不是真正的缓存。 I think you will have more luck finding the right solution by putting the idea of a cache to the side, and instead look at how you can build a persistent document store that has the functionality you require:我认为通过将缓存的想法放在一边,您会更幸运地找到正确的解决方案,而是查看如何构建具有所需功能的持久文档存储:

  • Purging old documents清除旧文件
  • Statistics about the documents being stored有关正在存储的文档的统计信息

As suggested by @djechlin, this is more of a design & architecture question that would be difficult to answer in this forum.正如@djechlin 所建议的,这更像是一个设计和架构问题,在本论坛中很难回答。

Best of luck.祝你好运。

Try Jboss' Cache: http://docs.jboss.org/jbossclustering/cluster_guide/5.1/html/jbosscache.chapt.html试试 Jboss 的缓存: http : //docs.jboss.org/jbossclustering/cluster_guide/5.1/html/jbosscache.chapt.html

it has eviction algorithm, persistent, it's free.它有驱逐算法,持久的,它是免费的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM