Im getting to where i need to consider caching for my web application. Im a bit courious as to how long time i should cache the items, so i would like to make some sorts of statistics on how often i use my cache vs how often i load data from my server. How to go about doing this? Should i do this manually with data caching, like this:
- Does the data exist in my cache
- No – load it into cache and return it
- Insert a row into my database for statistics
- Yes – use the data from the cache
- Insert a row into my database for statistics
To me it seems a bit odd to query the cache and then insert into my database, seems the performance gain is lost then – right?
What to do then?
Instead of looking at this problem as a sitewide problem, I would investigate those areas that are bottlenecks in your system, and consider caching those. The time you cache will depend on the data, and how frequently it changes.
Asp.net has some built in performance tools that will show you quite a bit of information about your cache
http://msdn.microsoft.com/en-us/library/ms972959.aspx
Don’t focus on the cache hits vs. misses. Start off by focusing on the data that is retrieved often, but changes very little.
This article has some good information on implementing a caching policy
http://www.c-sharpcorner.com/UploadFile/vishnuprasad2005/ImplementingCachinginASP.NET11302005072210AM/ImplementingCachinginASP.NET.aspx