Reputation: 61
I'm looking for a caching solution for a Java Web Application. We have an Oracle db instance and 2-3 instances that are remote to our db. We want to cache data locally to our app as we can't accept db response time. Our dataset is of average size (few thousands of row per table) and is modified manually (so not very often) from our application (no direct db access).
So what we've been thinking of is a solution that allows us to have all data that's needed locally. We'd like to reduce the amount of data being retrieved from db and rewritten to cache.
So for example, when one entity is modified, we don't want to invalidate all cached queries on that table, we'd rather want to be able to modify locally cached queries resultsets so query still can be run locally from cached data. Caches have to replicate their changes\retrieve data modified by other instances of application from db.
We've been looking at EhCache as a Hibernate 2nd level cache but it invalidates all cached queries for given table on any table modification. I took a quick look into Hibernate Services but don't know yet if that would allow us to override hibernate 2nd level cache default behavior to meet our needs.
Are there any other solutions that we could use?
Edit We want to have a very fast access to data. Effectively what we're looking for is a quaryable cache.
Upvotes: 4
Views: 849
Reputation: 1250
The invalidation of cached query result isn't something the cache does control, but is how Hibernate handles his QueryCache... Short of changing that code, I don't see how you'd do that. And besides, I don't think there is a better "suits all" solution to that problem frankly.
So if you want very specialized caching of query result, I guess you'd have to implement that yourself.
Also, if you need higher consistency guarantees, you probably will want to use clustered caches, rather than a replicated one...
Upvotes: 0
Reputation: 59
If you use EhCache and you have multiple application in clusters, you will have to use a mechanism (JMS, JGroups,...) for the data cache replication.
One thing you must be aware is that if you have another application not running in Java, the app won't be notified: JGroups is only available in Java and your non-Java app won't be able to invalidate a cached entity. The EhCache/Jgroups support allow you to set up the replication in ONE configuration file (no additional code require!)
It seems that you are looking for the "Update via Copy" feature of EhCache. Let me list one the configuration possibilities of EhCache:
Update via Copy vs Invalidation
Update Via Copy: Data sent to all nodes
Pros: Avoid a complete re-load of the cache
Cons: Incoherent data between nodes is possible & useless if the TTL of the cached data is low
Update via invalidation: Notification of invalidation sent to all nodes. If the data are already cached, nodes remove cached data query again the database.
Pros: Data consistency & Lighter in network traffic
Cons: Lot of database queries and it may result in a massive demand of data simultaneously
Async vs Sync
Async
Pros: quick reply & and data transmission
Cons: UDP...
Sync
Pros: Data integrity
Cons: Perf...
I hope it helped you to pick the right decision.
Upvotes: 2
Reputation: 2297
Have you checked out JBoss cache? You can define the eviction policies for your queries separately and also its very easy to sync between your cluster nodes. If you need you can read up on the article i compiled some time back on my experience if it is helpful for you ;
http://dinukaroshan.blogspot.com/2009/10/jboss-caching-integration.html
Upvotes: 3