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
4 Answers
Here are caching linksMSDN
Very good article for Beginners Exploring Caching
1 Comment
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?
4 Comments
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.
Comments
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