views:

3810

answers:

8

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.

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

A: 

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.

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

bmatthews68
+4  A: 

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.

dave
I agreee. One big annoyance of Ehcache (and Terracotta's other library, Quartz) is a "feature" that phones home on startup to check for updates. This is disable-able, but is enabled by default on startup. See http://adammonsen.com/post/512 for details.
Adam Monsen
+3  A: 

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.

+3  A: 

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

brad
+1  A: 

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.

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

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

willCode4Beer
+1  A: 

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.

StaxMan
+6  A: 

Judging by their releases page, OSCache has not been actively maintained for over 2 years. This is not a good thing. EhCache, on the other hand, is under constant development. For that reason alone, I'd choose EhCache.

skaffman
A: 

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

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).

I recently found out about this project -

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

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

Andrew B