Documentation Center

Configuring .NET client-side caching

Configure client-side caching on your .NET Web site by modifying the Web.config file.

Procedure

  1. In your .NET Web application, open Web.config for editing.
  2. Ensure that the configSections section contains a sectionGroup section with its name attribute set to sdl.web.delivery.
  3. Ensure that this sectionGroup section contains the following section section:
    <section name="caching" type="Sdl.Web.Delivery.Caching.CacheConfigurationSection, Sdl.Web.Delivery.Caching" allowLocation="true" allowDefinition="Everywhere" /> 
  4. Ensure the presence of a root-level section called sdl.web.delivery, containing a caching section inside it. Set the defaultHandler attribute of this caching element to the name of one of your cache handlers (see below). By default, unless configured otherwise, this cache handler will be caching the content.
  5. Create a handlers section inside the caching section. This handlers section must contain one or more add elements, specifying the various cache handlers.
  6. For each add subelement you create, set the type attribute to one of the following values:
    NullCacheHandler
    Perform no caching at all
    DefaultMemCacheHandler
    Perform default ASP.NET in-memory caching
    CoreMemCacheHandler
    Perform .NET Core in-memory caching
    RedisCacheHandler
    Perform .NET Core distributed caching using a Redis database
  7. If you set type to RedisCacheHandler, you can also specify the following further attributes:
    AttributeValue
    instanceThe name of a specific Redis instance for isolating caching data
    compressionA Boolean; set to false to disable compression when writing cache data. Defaults to true.
    compression_limitIf compression is set to true or omitted, set to the size, in number of bytes, of data before it should be compressed. Defaults to the value 256.
  8. Set the name attribute to a unique string. One of your add elements must have a name attribute equal to that of the defaultHandler attribute of the caching element.
  9. If you set type to RedisCacheHandler, also specify an endpoint child element within the add element, with a host attribute set to the Redis host IP address, and a port attribute set to the Redis port.
  10. To specify a global caching policy to determine cache eviction, specify a policy child element within the add element, and give it one of the following attributes:
    • Use the slidingExpiration attribute to remove items from the cache only if they are not being used for a set period of time. That period, in seconds, is the value of the attribute, and it defaults to the value 300.
    • Alternatively, use the absoluteExpiration attribute to remove items from the cache after a set period of time, regardless of whether they are being used or not. That period, in seconds, is the value of the attribute, and it has no default.

    If neither attribute is specified, a sliding expiration policy is applied by default, with its default timeout period of 300 seconds.

  11. Add further add elements as needed, to specify further handlers. For example, you could create different kind of handlers of the type DefaultMemCacheHandler, which differ in their expiration period, and call then shortLivedCache and longLivedCache.
  12. If you want to configure specific cache handling for specific kinds of data on your Web site, add a regions section, which is a sibling to the handlers section.
  13. Within the regions section, create one or more add elements to specify the type of data you want to handle separately. Each add element has the following attributes:
    cacheName

    The name of the cache handler to use for this type of data. The value must be that of a name attribute of one of the add elements inside the handlers section (and should be different from the value in the defaultName attribute of the caching element).

    name
    A string that identifies the type of data (the cache region) that you want this handler to cache. Possible values include:
    ValueDescription
    CIL-BROKERCache region that is used whenever the CIL makes a Content Broker API request
    CIL-DYNAMICCache region that is used whenever the CIL uses the Dynamic Content Delivery API
    CIL-LINKINGCache region that is used whenever the CIL makes a Linking API request to dynamically resolve links
    CIL-INTERNALCache region for anything else the CIL may go that uses a cache for performance reasons
  14. If you want the caching policy for this type of data to be different from the default policy, specify a region-specific caching policy to determine cache eviction, just like you did in step 10.
  15. Add further add elements as needed, to specify further regions.
  16. Save and close Web.config.
  17. Restart the Web site to apply your changes.