Java DAO caching

Posted by santiagobasulto on Stack Overflow See other posts from Stack Overflow or by santiagobasulto
Published on 2010-05-12T03:14:38Z Indexed on 2010/05/12 7:44 UTC
Read the original article Hit count: 252

Filed under:
|
|

I'm developing a medium Java app, and i'm facing a small problem due to my lack of experience.

I've a custom DAO, which gets "Article" objects from the Database. I've the Article class, and the DAO has a method called getArticle(int id), this method returns an Article. The Article has a Category object, and I'm using lazy loading.

So, when I request for an article's category (Article a = new Article(); a.getCategory();) the Article class gets the Category from the DAO and then returns it.

I'm now thinking to cache it, so when I request multiple times to an article's category, the database is only queried one time.

My question is: where should I put that cache? I can put it on the Article class (in the DTO), or I can put it on the DAO class.

What do you say?

© Stack Overflow or respective owner

Related posts about java

Related posts about database