views:

235

answers:

5

Are there any in-memory/caching solutions for java that allow for a form of Querying for specific attributes of objects in the Cache?

I realize this is something that a full blown database would be used for, but I want to be able to have the speed/performance of a cache with the Querying ability of a database.

+2  A: 

At first, HSQLDB came to mind, but that's an in-memory relational database rather than an object database. Might want to look at this list. There's a few object databases there, one of which might meet your needs.

Eric Petroelje
+1  A: 

Look at db4oat rather lightweight java object database. You can even query the data using regular java code:

List students = database.query( new Predicate(){
      public boolean match(Student student){
        return student.getAge() < 20
          && student.getGrade().equals(gradeA);}})

(From this article).

ordnungswidrig
+3  A: 

JBoss Cache has search functionality. It's called JBossCacheSearchable. From the site:

This is the integration package between JBoss Cache and Hibernate Search.

The goal is to add search capabilities to JBoss Cache. We achieve this by using Hibernate Search to index user objects as they are added to the cache and modified. The cache is queried by passing in a valid Apache Lucene query which is then used to search through the indexes and retrieve matching objects from the cache.

Main JBoss Cache page: http://www.jboss.org/jbosscache/

JBossCacheSearch: http://www.jboss.org/community/docs/DOC-10286

Steve Claridge
A: 

Another idea is to use Lucene and a RAMDirectory implementation of Directory to index what you put into your cache. That way, you can query using all the search engine query features which Lucene provides.

In your case, you will probably index the relevant properties of your objects as-is (without using an Analyzer) and query using a boolean equality operator.

Lucene is very lightweight, performant, thread-safe and memory consumption is low.

mhaller
+1  A: 

Terracotta or GBeans or POJOCache

John Ellinwood
Ok, strange. Somebody emailed me and told me to provide this link for pojocache: http://www.samaxes.com/2009/03/17/jboss-pojocache-configuration/? I don't see why they wouldn't just make that comment here themselves.
John Ellinwood