I want to know about the cache and how it is improve the performance of the site, can you provide a simple example to understand cache. Thank you
5 Answers
I'm not sure I understand the question but I'll try. All cache is is a "cheap" place to store data. I say cheap meaning it's faster to access than "expensive" locations. For instance you might cache data from a file on a drive (expensive, slow) into memory (cheap, fast) so it can be quickly accessed. Is that what you were asking?

- 8,868
- 4
- 48
- 68
-
Mr. Cory Charlton it is related to hardware but i want to about cache in asp.net in programming side – Surya sasidhar Dec 14 '09 at 04:25
-
Actually that's just what cache is in general. You could also use cache to store data that was "expensive" to compute. For instance if you had to run a calculation on a data set and 5 minutes later you recieved your results then you could cache the data in a temporary storage location so you could retrieve it "cheaply" next time. Maybe this will help: http://en.wikipedia.org/wiki/Cache – Cory Charlton Dec 14 '09 at 04:30
-
Cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (owing to longer access time) or to compute, compared to the cost of reading the cache. In other words, a cache operates as a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, it can be used in the future by accessing the cached copy rather than re-fetching or recomputing the original data. – Cory Charlton Dec 14 '09 at 04:31
-
Data you might cache in a common ASP.NET application might be data you retrieved from a SQL query. It took time for the SQL server to retrieve your dataset (expensive) but now that you have the data you can cache it in memory (cheap) and next time you need it you can get it almost instantly instead of waiting for the SQL server to process your query. Hope that helps. – Cory Charlton Dec 14 '09 at 04:33
Caching can take many different meaning for an ASP.Net application spread from the browser all the way to your hardware with the IIS, Application, Database thrown in the middle.
I think you wan't to know about application and session cache. You can also cache at Web Application tier using output caching at IIS level (in IIS 7) and ASP.Net level. This two cache are the one that you can control most and gives you good benefits while still simple to use.
On the other hand is in-memory distributed caching system. Apart from memcache and Appfabric (velocity), there are commercial solutions like NCache or Oracle Coherence. This level of caching promises scalability at a cheaper cost. It is expensive to scale the DB tier compared to this. You may have to consider aspects like network bandwidth though. This type of caching, specially with invalidation and expiry can be complicated.
Then there is caching going on at client web proxy tier that can be controlled by cache-control HTTP header.
Finally you have browser level caching, view state and cookies for small data.
Caching at infrastructure tiers like at Database level or SAN etc, is transparent to your application.

- 10,858
- 6
- 42
- 50
With ASP.NET Caching you can
- Cache entire response content for pages you include @Outputdirective in your page
You can do this programmatically using Response.Cache.SetExpires(DateTime.Now.AddSeconds(120));
You can cache portion of page by using OutputCache directive in Usercontrol
"Once you have enabled output caching, the initial HTTP GET request for the page places its dynamic content in the output cache for the amount of time you specify. The output cache satisfies subsequent GET, HEAD, or POST requests for that page until the amount of time you specify expires." MSDN
- Caching Application Data At its simplest you can: Cache["key"] = DateTime.Now.ToString(); // or a dataset
To retrieve string cachedValue = (string)Cache["key"]; To remove Cache.Remove("key");
Retrieving Values of Cached Items
Cache is created per app domain and is not user specific. Caching can easily improve performance up to 30%.
Useful SO links
This is a tutorial on ASP.NET Cache class.
It is used to store temporary data/objects.
http://msdn.microsoft.com/en-us/library/6hbbsfk6%28VS.80%29.aspx

- 60,503
- 9
- 116
- 147