Transactable and Threadsafe Java Object Cache

T

toqeer

Hi All
My question is regarding the need of another caching APIs or
framework.
In my last project we handled the transactions on business layer
controller, which commit or rollback the transaction based on the
success or error in updating the database. We were not using EJBs but
if I compare it with EJBs then it's like CMT for stateless session
EJBs. As this application was data intensive so we decided to
implement simple cache to hold read-only objects in memory. But
developers also used this simple solution for other objects. As a
result in business methods the developer update the cache if database
is updated successfully. Now the cache was read and updated through
out in application and soon updating and rolling back the cache become
complex and error prone.
Then we realised the importance of cache that can be used seamlessly
at persistence layer and satisfy some basic requirements like

Thread Safe
If multiple users are updating same object, cache should remain
consistent with DB, also if one object is being updated the other
thread will see the old copy (last committed copy) without blocking
itself.

Transact-able
If a transaction involves multiple objects to be updated in DB, each
object is updated in DB and cache independently. In case of error
during updating one of the object the business layer controller will
roll back the data base and also rollback the cache like
cache.rollback();

Seamless
No application layer code is aware of the cache accept the
persistence layer.

My emphasis was on thread-safe and transact-able cache, because it was
the main pain for us to manage through out the application. I tried my
best to find such cache, but didn't succeed. Then I decided to build
my own cache API to do the job and fortunately successfully built such
cache and we got rid of all nasty errors and code, our business layer
become simpler and error free. Initially I implemented READCOMMITTED
isolation level, as it was enough in my case.

Now I'm thinking to refactor and enhance the cache APIs so that it can
be used in other projects having same requirements and make it
open-source so that other developers can get benefit for it.
I'm not sure whether such thing is available already in the market.
I'm not sure whether such functionality has any importance for others.

I want some feedback from developer community regarding the importance
and redundancy of such work. So that I do not re-invent the wheel and
also do not spent my time on some thing won't help others.
Your feedback is very import for me.

Regards,
Toqeer Sardar.
 
C

Chris Smith

toqeer said:
My question is regarding the need of another caching APIs or
framework.

JCS or ehcache might be worth a look. I haven't looked through and
verified all of your requirements (and I probably won't), but those are
fairly common packages to do this. Certainly Hibernate is able to use
ehcache in an environment with transactions and such.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

toqeer

Chris Smith said:
JCS or ehcache might be worth a look. I haven't looked through and
verified all of your requirements (and I probably won't), but those are
fairly common packages to do this. Certainly Hibernate is able to use
ehcache in an environment with transactions and such.

Thanks for your feedback, I have looked at ehcache specially because
hibernate use this cache and also provide transaction facility. I have
not seen in the documentation that the ehcache provide the ability to
commit or rollback, also there is no information regarding if multiple
threads are reading/updating same object in cache.
So I assume that it's the Hibernate that provide the transaction
functionality not the ehcache.

Regards,
Toqeer Sardar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top