Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data caching

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always we talk about caching the data, fetched from the database. Suppose an user retrieves set of records matching his search criteria, if we cache the data, we can use the cache data provided, the same user or another user fires a same search criteria.So unless iam not sure of same search criteria, its of waste for me to cache the data. I just want to know whether my understanding is correct or wrong. If this "understanding is wrong" can any one please provide explaination links to caching.
Hari
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hari babu:
...So unless iam not sure of same search criteria, its of waste for me to cache the data.

Wait. Even if search criteria is the same, can't the results be different? What if the underlying data has been updated since the first search by another user?
Entity beans provides pessimistic caching and if you are using them, you are already making use of caching. If you like to design your own caching framework, consider some of the challenges -
The instance you cache any data, you accept the risk of working with "stale" data. A cache that cannot be updated is useless. But the question is, how frequently should you update the cache? And should you cache mostly dynamic data, or mostly static data? If the cost of maintaining the cache upto date outweighs the benefits of caching, then is it worth in the first place?
IMO you should first attempt to answer these questions in the context of your application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic