Overview Introduction to ASP.NET caching Output caching Fragment caching Data caching 1.
Caching Enhancement in ASP.NET 4.0
-
Upload
abhijit-jana -
Category
Technology
-
view
5.534 -
download
5
description
Transcript of Caching Enhancement in ASP.NET 4.0
virtual techdaysINDIA │ 9-11 February 2011
Caching Enhancement in ASP.NET 4.0
Abhijit Jana │ Consultant, Microsofthttp://abhijitjana.net
ASP.NET Caching Quick Tour Data / Object Caching Output Caching
Page Caching Fragment Caching
New Object Caching Option System.Runtime.Caching
Output Cache Provider in ASP.NET 4.0 Internals of Output Cache Provider Creating Custom Cache Providers Limitation
Selecting Cache Provider on the fly
virtual techdaysINDIA │ 9-11 February 2011
S E S S I O N A G E N D A
Caching is a technique where frequently used data and Web pages can stored temporarily.
It’s a great feature that reduces network latency and It can improve application's performance considerably. ASP.NET Caching
Data / Object Caching Output Caching
Page Output Caching Fragment Caching
virtual techdaysINDIA │ 9-11 February 2011
ASP.NET Caching Quick Tour
Basic of ASP.NET Caching
ASP.NET Caching is Implemented as HTTPModule Cache Module Listens to all the incoming Request OutputCacheModule listens to ResolveRquestCache and
UpdateRequestCache Based on the events modules returns the Cached HTML
content or moving forward to Page Handler Cache can have Dependencies
File based dependencies Time Based dependencies
virtual techdaysINDIA │ 9-11 February 2011
ASP.NET Caching Quick Tour
BeginRequest Event
AuthenticateRequest Event
AuthorizeRequest Event
ResolveRequestCache Event
Map Request Handler
AcquireRequestState Event
virtual techdaysINDIA │ │ 9-11 February 2011
ASP.NET Data – Object Caching
Request For Information
Request For Information
Cached Data
virtual techdaysINDIA │ │ 9-11 February 2011
New Object Caching API in ASP.NET 4.0
ASP.NET in-memory object cache (System.Web.Caching.Cache) with help of System.Web.dll
Same Cache Object Can be used for Win Forms , WPF based application with reference of System.Web.dll
.NET Framework 4 introduces a new assembly System.Runtime.Caching.dll The Assembly contains a new caching API in the System.Runtime.Caching
namespace. The new API mainly based on concrete in-memory object cache implementation
(System.Runtime.Caching.MemoryCache class). Win forms, WPF based application can use Caching with just help of
System.Runtime.Caching.dll . So, no need to load System.web.dll for non web applications.
virtual techdaysINDIA │ 22-24 November 2010
DEMO: New Object Caching API in ASP.NET 4.0
Abhijit Jana│ Consultant, Microsoft
virtual techdaysINDIA │ │ 9-11 February 2011
ASP.NET Output Caching Caches rendered markup of an ASP.NET page
Caches Complete Rendered Markup Caches Partial Markup Caching Substitution
Output caching can be configured based on duration, params Cached version of the page can be sent in response without running the page MSIL
JIT Compiler > Native Code > HTML
virtual techdaysINDIA │ │ 9-11 February 2011
ASP.NET Output Caching Continue…
ASPX Content
Cached Content
Web ServerClients
Request
Response
Request
Response
virtual techdaysINDIA │ │ 9-11 February 2011
ASP.NET Output Caching – Deep Dive
ASPX Page Handler
HTTP Module
HTTP Module
HTTP Module
ASP.NET Page
ASP.NET Engine
Page Class Instance
Cached Version
1. Full Page Cache2. Partial Page Cache
12
3
4 5
6 7
virtual techdaysINDIA │ │ 9-11 February 2011
ASP.NET Custom Output Cache Provider
Cache Provider
Output Caches Stored In Memory Extending ASP.NET Output Caching Custom Cache Provider Implements OutputCacheProvider Add() , Get(), Remove(), Set() Can be store File System, DB, In Memory, Cloud
CustomDiskCacheProviderHelper
OutputCacheProvider
Class
Methods
Add
Get
Remove
Set
virtual techdaysINDIA │ 22-24 November 2010
DEMO: Creating Custom Output Cache Provider
Abhijit Jana│ Consultant, Microsoft
virtual techdaysINDIA │ │ 9-11 February 2011
Limitations
Supported File dependencies but no custom dependencies. Custom Cache providers only supports Absolute expiration . There is no supports for
sliding expiration.
virtual techdaysINDIA │ │ 9-11 February 2011
Selecting Cache Provider On the Fly
If you have multiple Cache Provider you can select any of the at runtime based on your requirements.
Can set default Provider.
Disk Cache Provider
Database Cache Provider
In Memory Cache ( Default Provider )
Get Cache Provider
virtual techdaysINDIA │ 22-24 November 2010
DEMO: Dynamically Output Cache Provider SelectionAbhijit Jana│ Consultant, Microsoft
virtual techdaysINDIA │ │ 9-11 February 2011
Summarize
Caching is a technique where frequently used data and Web pages can stored temporarily.
ASP.NET having Data Caching and Output Caching with Cache Dependency .NET 4.0 Introduce new Object Caching for ASP.NET 4.0 Using System.Runtime.Caching Internal of Output Caching in ASP.NET Creating Custom Cache Provider using OutputCacheProvider Select Cache Provider on the Fly
virtual techdaysINDIA │ 9-11 February 2011
Resource
Microsoft ASP.NET 4 Core Runtime for Web Developers Scaling Your Data Tier with Windows Server AppFabric http://msdn.microsoft.com/en-us/library/dd997357.aspx http://
msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx
virtual techdaysTHANKS│ 9-11 February 2011
[email protected] │ http://abhijitjana.net │ @AbhijitJanaThank You