In this blog, I will write about Caching in ASP.net.
What is caching in ASP.Net?
With careful optimization, you can reduce the time and reduce the burden imposed on the database to a certain extent, but you can never eliminate it. But with a system that uses caching, some data requests won’t require a database connection and a query. Instead, they’ll retrieve the information directly from server memory, which is a much faster proposition.
Types of Caching
ASP.NET really has two types of caching. Your applications can and should use both types because they complement each other:
• Output caching: This is the simplest type of caching. It stores a copy of the final rendered HTML page that is sent to the client. The next client that submits a request for this page doesn’t actually run the page. Instead, the final HTML output is sent automatically. The time that would have been required to run the page and its code is completely reclaimed.
<%@ OutputCache Duration=”20″ VaryByParam=”None” %>
• Data caching: This is carried out manually in your code. To use data caching, you store important pieces of information that are time-consuming to reconstruct (such as a DataSet retrieved from a database) in the cache. Other pages can check for the existence of this information and use it, thereby bypassing the steps ordinarily required to retrieve it. Data caching is conceptually the same as using application state, but it’s much more server-friendly because items will be removed from the cache automatically when it grows too large and performance could be affected. Items can also be set to expire automatically.