Wednesday, 11 December 2013

Caching

1. What is Caching?
    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.
<%@ OutputCache Duration="60" VaryByParam="txtname" %>

2. 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 :-
  •    File dependency - Allows you to invalidate a specific cache item when a disk based file or files change.
  •    Time-based expiration - Allows you to invalidate a specific cache item depending on predefined time.
  •    Key dependency - Allows you to invalidate a specific cache item depending when another cached item changes.

3. 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.

4. 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.

5. 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.

6. Prevents the browser from caching the ASPX page.
HttpCachePolicy.SetNoStore() or Response.Cache.SetNoStore
  
7. How many types of caching using in asp.net?
  •  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
  •  Page Fragment Caching - If parts of the page are changing, then you can wrap the static sections as user controls and cache the user controls using page fragments caching.
  •  Data Caching - Data caching is a used for storing the Data objects on cache in a Key-Value based cache. We can use this to store the data that need to cache.

8. Caching Attribute
   DiskCacheable, NoStore, CacheProfile, VaryByParam, VaryByHeader, VaryByCustom, Location,  Duration

9. How is Caching extended in asp.Net 4.0?
  Output Cache in earlier versions of ASP.Net has a limitation - generated content always has to be  stored in memory, and on servers that are experiencing heavy traffic, the memory consumed by output caching can compete with memory demands from other portions of a Web application.
  ASP.NET 4 adds an extensibility point to output caching that enables you to configure one or more custom output-cache providers.
  Output-cache providers can use any storage mechanism to persist HTML content. This makes it possible to create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines.

10. How do you implement custom output caching?
Create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type.
You can then configure the provider in the Web.config file by using the new providers subsection of the outputCache element, as shown below:
                <caching>
                  <outputCache defaultProvider="AspNetInternalProvider">
                    <providers>
                      <add name="DiskCache"
                          type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/>
                    </providers>
                  </outputCache>
                </caching>
Then specify the newly created and configured custom cache provider as below:
<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>

No comments:

Post a Comment