G.ASP.Net Caching

  1. Application Caching (OR Object Caching),

    1. This which allows you to cache data you generate, such as a DataSet object or a custom report business object.

      1. Suggested way is to use HttpRuntime.Cache Property because it automatically manage memory and generate notifications.

  2. Page output caching, which saves the output of page processing and reuses the output instead of re-processing the page when a user requests the page again. It further has two variants

    1. Whole Page Caching : It is implemented via "@ OutputCache" page directive.

    2. Partial Page Caching (Control Caching) : Is implemented via user controls.

  1. Cache Providers (Extensible Output Caching) : ASP.NET adds extensiblity 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. These storage options can include local or remote disks, cloud storage, and distributed cache engines.

  2. Related Concepts

    1. Scavenging : Scavenging is the process of deleting items from the cache when memory is scarce. Items are removed when they have not been accessed in some time or when items are marked as low priority when they are added to the cache. ASP.NET uses the CacheItemPriority object to determine which items to scavenge first. For more information, seeHow to: Add Items to the Cache.

    2. Expiration : In addition to scavenging, ASP.NET automatically removes items from the cache when they expire. When adding an item to the cache, you can set it to expire as described in the following table.There is two types of Expiration Sliding and Fixed

    3. Cache Dependencies Management:

        1. You can configure an item's lifetime in the cache to be dependent on other application elements such as files or databases.

        2. When the element that a cache item depends on changes, ASP.NET removes the item from the cache.

      1. ASP.NET caching supports five types of dependencies

        1. Key dependency

        2. File dependency

        3. SQL dependency

        4. Aggregate dependency

        5. Custom dependency

    1. Cache Item Removal Notification You can be notified when an item is removed from the application cache so that you can replace it immediately.

  1. Video Tutorials

  1. How To Task

  1. Hands-on Lab

  1. Related Discussions

    1. Scenarios when Output caching might not work

      1. Large responce >250 KB

        1. Disabling Responce Buffer

        2. Set-Cookie Responce Header >> Set Responce Header to Shareble proprty true http://msdn.microsoft.com/en-us/library/system.web.httpcookie.shareable(v=vs.110).aspx

        3. No-Cache, No-Store , Vary Directive

        4. Requires Authentication to Access Resources

    2. Caching changes across various DOT.Net Version

      1. Unified Caching in Framework 4.0In the .NET Framework 3.5 and earlier versions, ASP.NET provided an in-memory cache implementation in the System.Web.Caching namespace.

      2. In previous versions of the .NET Framework, caching was available only in the System.Web namespace and therefore required a dependency on ASP.NET classes.

      3. In the .NET Framework 4, the System.Runtime.Caching namespace contains APIs that are designed for both Web and non-Web applications.

  1. Additional References