I’m new to cache and haven’t used it on my projects. I would like to know about what is best practice in caching.
Should caching be done while developing or finish development then cache everything?
1
In this case, caching is an example of premature optimization. So that would imply it’s a bad idea.
You don’t know where your performance bottlenecks will be yet, so applying caching now would be a mistake.
Get the application working first, run some performance analysis, and then start using caching were appropriate.
So that means to get the development mostly done, and as part of your refactoring / refinement work you’ll identify where the performance issues are.
1
You should build in the Caching of data whenever it logically comes up in development, but its true that you don’t want to be sitting around waiting for the Cache to expire while you are doing dev.
One solution would be to set the Cache duration in a configuration setting (xml, etc), and once you are satisfied that it works with whatever production setting you will likely use (10min, 1 hour, 1 day, whatever), turn it down to something like 1 second in the config, so that you can continue with dev. That way, changing the Cache expiration back up to the ‘real’ value won’t involve a code change.