Configuring .NET client-side caching
Configure client-side caching on your .NET Web site by modifying the Web.config file.
Procedure
- In your .NET Web application, open Web.config for editing.
- Ensure that the
configSectionssection contains asectionGroupsection with itsnameattribute set tosdl.web.delivery. - Ensure that this
sectionGroupsection contains the followingsectionsection:<section name="caching" type="Sdl.Web.Delivery.Caching.CacheConfigurationSection, Sdl.Web.Delivery.Caching" allowLocation="true" allowDefinition="Everywhere" /> - Ensure the presence of a root-level section called
sdl.web.delivery, containing acachingsection inside it. Set thedefaultHandlerattribute of thiscachingelement to the name of one of your cache handlers (see below). By default, unless configured otherwise, this cache handler will be caching the content. - Create a
handlerssection inside thecachingsection. Thishandlerssection must contain one or moreaddelements, specifying the various cache handlers. - For each
addsubelement you create, set thetypeattribute 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
- If you set
typetoRedisCacheHandler, you can also specify the following further attributes:Attribute Value instanceThe name of a specific Redis instance for isolating caching data compressionA Boolean; set to falseto disable compression when writing cache data. Defaults totrue.compression_limitIf compressionis set totrueor omitted, set to the size, in number of bytes, of data before it should be compressed. Defaults to the value 256. - Set the
nameattribute to a unique string. One of youraddelements must have anameattribute equal to that of thedefaultHandlerattribute of thecachingelement. - If you set
typetoRedisCacheHandler, also specify anendpointchild element within theaddelement, with ahostattribute set to the Redis host IP address, and aportattribute set to the Redis port. - To specify a global caching policy to determine cache eviction, specify a
policychild element within theaddelement, and give it one of the following attributes:- Use the
slidingExpirationattribute 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
absoluteExpirationattribute 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.
- Use the
- Add further
addelements as needed, to specify further handlers. For example, you could create different kind of handlers of the typeDefaultMemCacheHandler, which differ in their expiration period, and call thenshortLivedCacheandlongLivedCache. - If you want to configure specific cache handling for specific kinds of data on your Web site, add a
regionssection, which is a sibling to thehandlerssection. - Within the
regionssection, create one or moreaddelements to specify the type of data you want to handle separately. Eachaddelement 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
nameattribute of one of theaddelements inside thehandlerssection (and should be different from the value in thedefaultNameattribute of thecachingelement). name-
A string that identifies the type of data (the cache region) that you want this handler to cache. Possible values include:
Value Description 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
- 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.
- Add further
addelements as needed, to specify further regions. - Save and close Web.config.
- Restart the Web site to apply your changes.