Monday 2 January 2012

Cache


What is an application object?
Application object ca be n used in situation where we want data to be shared across users globally.
What’s the difference between Cache object and application object?
The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies.
How can get access to cache object?
The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object.
What are dependencies in cache and types of dependencies?
When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update. Following are the supported dependency :-

1. File dependency - Allows you to invalidate a specific cache item when a disk based file or files change.
2. Time-based expiration - Allows you to invalidate a specific cache item depending on predefined time.
3. Key dependency - Allows you to invalidate a specific cache item depending when another cached item changes.
What is Cache Callback in Cache?
Cache object is dependent on its dependencies example file based, time based etc. Cache items remove the object when cache dependencies change.ASP.NET provides capability to execute a callback method when that item is removed from cache.
What is scavenging?
When server running your ASP.NET application runs low on memory resources, items are removed from cache depending on cache item priority. Cache item priority is set when you add item to cache. By setting the cache item priority controls the items scavenging are removed first.
What are different types of caching using cache object of ASP.NET?
You can use two types of output caching to cache information that is to be transmitted to and displayed in a Web browser:
1. Page Output Caching - Page output caching adds the response of page to cache object. Later when page is requested page is displayed from cache rather than creating the page object and displaying it. Page output caching is good if the site is fairly static.
2. Page Fragment Caching - If parts of the page are changing, you can wrap the static sections as user controls and cache the user controls using page fragment caching.
How can you cache different version of same page using ASP.NET cache object ?
Output cache functionality is achieved by using "OutputCache" attribute on ASP.NET page header. Below is the syntax:
<%@ outputcache duration="20" location="Server" varybyparam="state" varybycustom="minorversion" varybyheader="Accept-Language" %>
1. VaryByParam - Caches different version depending on input parameters send through HTTP POST/GET.
2. VaryByHeader - Caches different version depending on the contents of the page header.
3. VaryByCustom - Lets you customize the way the cache handles page variations by declaring the attribute and overriding the GetVaryByCustomString handler.
4. VaryByControl - Caches different versions of a user control based on the value of properties of ASP objects in the control.
How will implement Page Fragment Caching?
Page fragment caching involves the caching of a fragment of the page, rather than the entire page. When portions of the page are need to be dynamically created for each user request this is best method as compared to page caching. You can wrap Web Forms user control and cache the control so that these portions of the page don’t need to be recreated each time.



No comments:

Post a Comment