Explain How to to use cache in asp.net for cache
Explain How to to use cache in asp.net for cache
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
In ASP.NET (non-Core), caching is a powerful feature to improve performance by storing data temporarily. You can cache data, pages, or fragments of pages.
1. Using
HttpRuntime.Cache/HttpContext.Cache(In-Memory Cache)Best for caching data like query results or processed objects.
Example: Caching Data in Code
2. Cache Insert with Callback (Auto Remove Notification)
3. Page Output Caching (Full Page Cache)
Caches the entire HTML output of a page.
In ASPX Page:
Duration="60": cache for 60 seconds.VaryByParam="none": same cache for all query parameters.4. Fragment Caching (User Control or Partial Cache)
Useful if part of your page changes often, but other parts don’t.
Example in ASPX User Control:
Include this user control in your page:
5. Cache with Dependencies (Auto Invalidate on File/DB Change)
Cache is cleared if the XML file changes.
6. Remove from Cache
Note
Summary Table
HttpContext.Current.Cache<%@ OutputCache %>directive.aspxpages<%@ OutputCache %>in user control.ascxcontrolsCacheDependencyCache.Remove(key)