Explain File-based Dependency And Key-based Dependency.

Explain File-based Dependency And Key-based Dependency.


  • 26 May, 2013

    Cache Dependency

    Using cache dependency, we can set the dependency of the cache with some data or entity that might change. So we can set the dependency of cache by which we can update/remove cache. There are three types of dependencies supported in ASP.NET:

    • File based dependency
    • Key based dependency
    • Time based dependency

    File Based Dependency: File-based dependency invalidates a particular cache item when a file(s) on the disk changes.

    Using cache dependency, we can force ASP.NET to expire cached data items from the cache when the dependency file changes. We can set the dependency to multiple files also. On such cases, the dependency should be built from an array of files or directories.

    Use: File based dependency is very useful when you need to update data that is displayed to the user based on some changes on a file. For example, a news site always shows data from a file, and if some breaking news comes, they just update the file and the cache should expire, and during the expiry time, we can reload the cache with updated data using OnRemoveCallBack.

    Key Based Dependency: Key-based dependency invalidates a particular cache item when another cache item changes.

    Use: This is useful when we have multiple interrelated objects in the cache and if one of the objects changes, we need to updated or expire all of them.

    Time Based Dependency: Time-based dependency causes an item to expire at a defined time. The Cache.Insert() method of the Cache class is used to create a time-based dependency. Two types of time based dependency are available.

    • Absolute
    • Sliding

    Absolute: Sets an absolute time for a cache item to expire. Absolute expirations are specified in full-time format (hh:mm:ss). The object will be expired from the cache at the specified time.

    Sliding: Resets the time for the item in the cache to expire on each request. This is useful when an item in the cache is to be kept alive so long as requests for that item are coming in from various clients.

    In addition to these dependencies, ASP.NET allows the following:

    Automatic expiration: The cache items that are underused and have no dependencies are automatically expired.

    Support for callback: The cache object can be configured to call a given piece of code that will be executed when an item is removed from the cache. This gives you an opportunity to update the cache. We can use OnRemoveCallback().

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.