Java DAO caching
- by santiagobasulto
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?