3. Introduction:
• Caching is a technique of storing frequently used
data/information in memory, so that, when the same
data/information is needed next time, it could be
directly retrieved from the memory instead of being
generated by the application.
4. • Caching places frequently used data in quickly accessed media such as the
random access memory of the computer. The ASP.NET runtime includes a
key-value map of CLR objects called cache. This resides with the application and
is available via the HttpContext and System.Web.UI.Page.
• The data will not be available in the following cases:
• If its lifetime expires
• If the application releases its memory
• If caching does not take place for some reason
You can access items in the cache using an indexer and may control the lifetime
of objects in the cache and set up links between the cached objects and their
physical sources.
Continue:
5. What a Cache does
• A cache simply stores the output
generated by a page in the
memory and this saved output (cache)
will serve us (users) in the future.
7. Page Caching
• When we compile our code it is first it compiled into Microsoft Int
ermediate Language (MSIL) then The MSIL is converted into Native
Code using the JIT Compiler. Now if there is a page that changes fr
equently then the JIT needs to compile it every time. So, rather tha
n generate a page on each request we can cache the page using Pa
ge Output Caching so that it can be accessed from the cache itself.
< %@OutputCache Duration= "60" VaryByParam= "DepartmentI
d"% >
All the attributes that we specify in an OutputCache directive are u
sed to populate an instance of the System.Web.HttpCachePolicy cl
ass. Moreover, It is good if the website is fairly static.
8. Page Fragment Caching
• ASP.NET provides a mechanism for caching portions of pages,
called page fragment caching . For example: user control. To ca
che a portion of a page, you must first encapsulate the portion
of the page you want to cache into a user control . In the user
control source file, add an OutputCache directive specifying the
Duration and VaryByParam attributes. When that user control is
loaded into a page at runtime , it is cached, and all subsequent
pages that reference that same user control will retrieve it from
the cache.
9. Data Caching
• Data Caching is used to fetch the information of an application quickly based o
n the requirements. Cache object is just like application object which can be acc
ess anywhere in the application. The lifetime of the cache is equivalent to the lif
etime of the application. Caching data can dramatically improve the performance
of an application by reducing database contention and round-trips .