Redis / Distributed caching and Kentico 13 API integration

Noam Rinat asked on June 7, 2021 21:17

We are interested in using a distributed cache (Redis) for our Xperience 13 MVC site. The site will be hosted in a web farm on Azure (geo-replicated) so in-memory caching is not an optimal solution. We like the Kentico API and the integration with IPageCacheBuilder because of the ability to invalidate the cache when a dependency is changed on the admin site. We would like to leverage the IPageCacheBuilder in a way that the cached pages will be saved directly on Redis rather than in memory. In other words, we want the following code to cache the result in Redis:

return pageRetriever.Retrieve<Blog>(
    query => query
        .Path(nodeAliasPath, PathTypeEnum.Children)
        .TopN(count)
        .Culture(culture)
        .OrderByDescending("BlogDate"),
    cache => cache
        .Key($"{nameof(BlogRepository)}|{nameof(GetBlogs)}|{nodeAliasPath}|{count}|{culture}")
        .Dependencies((_, builder) => builder.PagePath(nodeAliasPath, PathTypeEnum.Children)));

Is that possible at all? What's the best way to have the result cached in a distributed cache without haveing to manage 2 sets of cache: in-memory and distributed?

Recent Answers


Sean Wright answered on July 6, 2021 23:24 (last edited on July 6, 2021 23:25)

@Noam,

The IPageRetriever uses IProgressiveCache internally to do caching.

You can re-implement this type and override Xperience's DI registration with your 'Redis' implementation of the CMS.Helpers.IProgressive cache interface.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.