ASP.NET - Why should we avoid use of Caching in asp.net C# project

Asked By bhanupratap singh on 23-Apr-14 08:13 AM
Hello Mr. Bobe

Should we avoid using Caching. if yes then Why ?
Some body say it cache data loads in memory so it become heavy. is it right. If yes the why cache control has made.
One thing more. If is use cache and if user closed browser then how should I clear data from memory to those cached data.
thanks

Robbe Morris replied to bhanupratap singh on 23-Apr-14 10:15 AM
Memory on servers is there to be used and it is cheap.  As a general rule, you want to cache as much relatively static data as possible (look up lists, etc.)  Also caching individual records is fine too.  You just have to have a mechanism to clear the cache or update the record in cache.  You also have to be mindful of traffic and whether you have enough memory to handle the load.  You can make some educated guesses by knowing the byte size of a typical record or cached element * the number of expected users on the site at peak times.

The cache, like any other tool, is meant to be used properly.  Blanket statements like "do not cache data because it takes memory" are stupid and typically spoken by developers who are not anywhere near as smart as they think they are.

You can site timeouts on cached items.

You cannot "reliably" empty the cache when someone closes their browser because you cannot "reliably" always tell when a browser has been closed, redirected to another url, or the session has expired (this event should but does not "always" fire).
bhanupratap singh replied to Robbe Morris on 24-Apr-14 06:46 AM
Thanks for reply.
You mean I should use cache.