Caching is a technique to save frequently used data into into temporary location. Improves application performance. Reduce a lot of server resources at peak times.
2. Agenda
●
Basics of ASP.NET Caching
●
Types of Caching
●
Output Caching
●
Full Page Caching
●
Partial (Fragment) Caching
●
Application (Object) Caching
●
System.Runtime.Caching
●
Custom cache providers
●
Some other caching techniques
●
Caching consideration
3. Basics of ASP.NET Caching
●
Caching is a technique to save frequently
used data into into temporary location.
●
Improves application performance.
●
Reduce a lot of server resources at peak
times.
●
Types of Caching
◦ Output Caching
●
Full Page Caching
●
Partial (Fragment caching)
◦ Application (Object) caching
4. Output Caching
●
Output caching enable to store rendered
HTML.
●
@ OutputCache directive is used to cache.
●
OutputCache attributes:
◦ Duration (time duration in seconds)
◦ VaryByParam (Cache by parameters)
◦ VaryByControl (Cache by controls)
◦ VaryByHeader (Cache by header Ex: User-Agent)
◦ VaryByCustom (GetVaryByCustomString on
Global.asax)
5. Output Caching...
●
OutputCache attributes:
◦ VaryByContentEncoding ( Ex: text/plain , text/html )
◦ Location
●
Server ( Output is saved under Web server memory )
●
Downstream ( Header is added to response to cache
on proxy server )
●
Client ( Header is added to response to cache on page
level )
●
Any ( Could be stored on any location ) - Default
●
None ( No caching is done )
6. Fragment Caching
●
Partial-page caching can work through user
control caching and post-cache substitution.
●
A portion of the page get cached.
●
Done through help of user controls or
substitution controls like AdRotator
●
Shared attribute is only available for user
control for sharing cache across multiple
pages.
7. Application/Object Caching
●
The application cache provides a
programmatic way for you to store arbitrary
data in memory using key/value pairs. Using
the application cache is like using application
state.
●
System.Web.Caching assembly
●
Depends upon HttpContext
●
Functions
◦ Cache.Insert
◦ Cache.Add
8. System.Runtime.Caching
●
System.Web.Caching.Cache is used with help
of System.Web.dll
●
New API came with .NET 4.0 under
System.Runtime.Caching.dll with
System.Runtime.Caching
●
It could be used in Win Forms, WPF etc
without making reference to System.Web.dll
●
The new API is based on in memory cache.
●
Write once and can be used in different .NET
technologies.
9. Custom Cache Provider
●
Output Caching are in memory.
●
Functionality came with ASP.NET 4.0
●
Implements OutputCacheProvider.
●
Add(), Get(), Set(), Remove() functions are
available for operation
●
Through custom cache provider cache could
be stored in File system, Cloud, database,
memory.
●
Helpful under scavenging process (removing
of cache when server memory is getting low).
10. Custom Cache Provider...
●
Output Caching are in memory.
●
Functionality came with ASP.NET 4.0
●
Implements OutputCacheProvider.
●
Add(), Get(), Set(), Remove() functions are
available for operation
●
Through custom cache provider cache could
be stored in File system, Cloud, database,
memory.
●
Helpful under scavenging process (removing
of cache when server memory is getting low).
Cache Provider
Add Get Set Remove
DB Files
12. Other techniques
●
Profile Caching under web.config to be
consistent with different setting.
●
GlobalOutputCacheProviderName in
Global.asax to change cache providers
according to need.
●
SQLCacheDependency has very limited
support and also depends upon SQL
configuration too.
http://blogs.msdn.com/b/tolong/archive/2007/02/16/sql-cache-dependency.aspx
http://www.codeproject.com/Articles/12335/Using-SqlDependency-for-
data-change-events
13. Caching Consideration
●
Full page caching: If page contents changes
after certain interval.
●
Fragment caching: Some of page contents
remains static but others are frequently
changes.
●
Object caching: Data is accessed frequently
and takes time to load up.
●
Cache dependency: File, Directory or based
on other cache entries.
●
Sliding or Absolute: Sliding, if data is not
changed frequently.