Java OSCache 与 EHCache

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/97741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:16:19  来源:igfitidea点击:

OSCache vs. EHCache

javacachingehcacheoscache

提问by bmw0128

Never used a cache like this before. The problem is that I want to load 500,000 + records out of a database and do some selecting/filtering wicked fast.

以前从未使用过这样的缓存。问题是我想从数据库中加载 500,000 多条记录并快速进行一些选择/过滤。

I'm thinking about using a cache, and preliminarily found EHCacheand OSCache, any opinions?

正在考虑使用缓存,初步找到了EHCacheOSCache,大家有什么意见吗?

采纳答案by dave

They're both pretty solid projects. If you have pretty basic caching needs, either one of them will probably work as well as the other.

它们都是非常可靠的项目。如果您有非常基本的缓存需求,它们中的任何一个都可能与另一个一样工作。

You may also wish to consider doing the filtering in a database query if it's feasible. Often, using a tuned query that returns a smaller result set will give you better performance than loading 500,000 rows into memory and then filtering them.

如果可行,您可能还希望考虑在数据库查询中进行过滤。通常,与将 500,000 行加载到内存中然后对其进行过滤相比,使用返回较小结果集的优化查询可以获得更好的性能。

回答by Brian Matthews

I mainly use EhCache because it used to be the default cache provider for Hibernate. There is a list of caching solutions on Java-Source.net.

我主要使用 EhCache,因为它曾经是 Hibernate 的默认缓存提供程序。Java-Source.net上有一个缓存解决方案列表。

I used to have a link that compared the main caching solutions. If I find it I will update this answer.

我曾经有一个比较主要缓存解决方案的链接。如果我找到它,我会更新这个答案。

回答by user14438

It sort of depends on your needs. If you're doing the work in memory on one machine, then ehcache will work perfectly, assuming you have enough RAM or a fast enough hard disk so that the overflow doesn't cause disk paging/thrashing. if you find you need to achieve scalability, even despite this particular operation happening a lot, then you'll probably want to do clustering. JGroups /TreeCache from JBoss support this, so does EHcache (I think), and I know it definitely works if you use Ehcache with terracotta, which is a very slick integration. This answer doesn't speak directly to the merits of EHcache and OSCache, so here's that answer: EHcache seems to have the most inertia (used to be the default, well known, active development, including a new cache server), and OSCache seemed (at least at one point) to have slightly more features, but I think that with the options mentioned above those advantages are moot/superseded. Ah, the other thing I forgot to mention is that transactionality of the data is important, and your requirements will refine the list of valid choices.

这有点取决于您的需求。如果您在一台机器上在内存中进行工作,那么 ehcache 将完美运行,假设您有足够的 RAM 或足够快的硬盘,以便溢出不会导致磁盘分页/抖动。如果您发现需要实现可伸缩性,即使这种特定操作经常发生,那么您可能想要进行集群。JBoss 的 JGroups /TreeCache 支持这一点,EHcache 也是如此(我认为),而且我知道如果您将 Ehcache 与 terracotta 一起使用,它肯定会起作用,这是一个非常巧妙的集成。这个答案并没有直接说明 EHcache 和 OSCache 的优点,所以这里的答案是:EHcache 似乎具有最大的惯性(曾经是默认的、众所周知的、积极的开发,包括一个新的缓存服务器),和 OSCache 似乎(至少在某一点上)具有更多的功能,但我认为通过上面提到的选项,这些优势没有实际意义/被取代。啊,我忘记提及的另一件事是数据的事务性很重要,您的要求将完善有效选择的列表。

回答by Brad at Kademi

I've used JCS (http://jakarta.apache.org/jcs/) and it seems solid and easy to use programatically.

我使用过 JCS ( http://jakarta.apache.org/jcs/) 并且它看起来很可靠并且易于以编程方式使用。

回答by willCode4Beer

Either way, I recommend using them with Spring Modules. The cache can be transparent to the application, and cache implementations are trivially easy to swap. In addition to OSCache and EHCache, Spring Modules also support Gigaspaces and JBoss cache.

无论哪种方式,我都建议将它们与 Spring 模块一起使用。缓存可以对应用程序透明,并且缓存实现非常容易交换。除了 OSCache 和 EHCache,Spring Modules 还支持 Gigaspaces 和 JBoss 缓存。

As to comparisons.... OSCache is easier to configure EHCache has more configuration options

至于比较.... OSCache 更容易配置 EHCache 有更多的配置选项

They are both rock solid, both support mirroring cache, both work with Terracotta, both support in-memory and to-disk caching.

它们都坚如磐石,都支持镜像缓存,都与 Terracotta 一起使用,都支持内存和磁盘缓存。

回答by StaxMan

Other answers discuss pros/cons for caches; but I am wondering whether you actually benefit from cache at all. It is not quite clear exactly what you plan on doing here, and why a cache would be beneficial: if you have the data set at your use, just access that. Cache only helps reuse things between otherwise independent tasks. If this is what you are doing, yes, caching can help. But if it is a big task that can carry along its data set, caching would add no value.

其他答案讨论了缓存的优缺点;但我想知道您是否真的从缓存中受益。不太清楚您计划在这里做什么,以及为什么缓存会是有益的:如果您有使用的数据集,只需访问它。缓存仅有助于在其他独立的任务之间重用事物。如果这是您正在做的事情,是的,缓存可以提供帮助。但是,如果这是一项可以承载其数据集的大任务,则缓存不会增加任何价值。

回答by skaffman

Judging by their releases page, OSCache has not been actively maintained since 2007. This is not a good thing. EhCache, on the other hand, is under constant development. For that reason alone, I would choose EhCache.

从他们的发布页面来看,OSCache 自 2007 年以来就没有得到积极维护。这不是一件好事。另一方面,EhCache 正在不断发展。仅出于这个原因,我会选择 EhCache。

Edit Nov 2013: OSCache, like the rest of OpenSymphony, is dead.

2013 年 11 月编辑:与 OpenSymphony 的其余部分一样,OSCache 已死。

回答by Andrew B

I have used oscache on several spring projects with spring-modules, using the aop based configuration.

我已经使用基于 aop 的配置在几个带有 spring-modules 的 spring 项目中使用了 oscache。

Recently I looked to use oscache + spring modules on a Spring 3.x project, but found spring-modules annotation-based caching is not supported (even by the fork).

最近我在一个 Spring 3.x 项目上看使用 oscache + spring modules,但是发现 spring-modules 基于注解的缓存不被支持(甚至被 fork 支持)。

I recently found out about this project -

我最近发现了这个项目 -

http://code.google.com/p/ehcache-spring-annotations/

http://code.google.com/p/ehcache-spring-annotations/

Which supports spring 3.x with declarative annotation-based caching using ehcache.

它支持 spring 3.x 和使用 ehcache 的基于声明性注释的缓存。

回答by sateeshkn

Choose a cache which complies to JSR 107 which will make your job easy when you want to migrate from one implementation to the other. To be specific on the question go for Ehcache which is more popular and widely used Java caching solution. We are using Ehcache extensively and it works for us.

选择符合 JSR 107 的缓存,当您想从一种实现迁移到另一种实现时,这将使您的工作变得轻松。要具体解决这个问题,请选择 Ehcache,它是更流行和广泛使用的 Java 缓存解决方案。我们正在广泛使用 Ehcache,它对我们有用。

回答by Slava Imeshev

OSCache is pretty much dead as it has been abandoned a few years ago. You may take a look at Cacheonix, it's been actively developed and we've just released v.2.2.2 with support for caching in the web tier. I'm a committer so you can reach out if you have any questions.

OSCache 几乎已经死了,因为它在几年前已经被放弃了。您可以看看 Cacheonix,它一直在积极开发中,我们刚刚发布了 v.2.2.2,支持 Web 层缓存。我是提交者,因此如果您有任何问题,可以联系我们。