MVC cache dependency via web farm

Chibin Zhang asked on October 9, 2019 07:27

Hi, I'd like to know more about the MVC cache dependency. Note: the Kentico version we are using is 12 sp.

From this article, I know that the MVC site cache dummy key is touched by a web farm mechanism between the CMS portal. However I have a few questions:

  1. Is the Kentico MVC caching always in memory cahcing? In one of our environments we have Azure redis cache enabled, however in the Storing session state data in an Azure environment only session data is mentioned, not the cache. The interesting part is, even thought the content are similar, the Kentico 11 documentation is actually Storing cache and session state data in Azure environment which has "cache" in the title.
  2. In a single instance scenario, where there is one MVC site application and one CMS portal application without redis cache and web farm is disabled, does the sync mechanism between the MVC site and the CMS portal still work?
  3. We are using MVC widgets. In the dancing goat solution, the widget controller has their own output cache, while the page controllers do not have dependencies on the widgets explicitly. So if one of the widget changes, will the page cache be invalid?

Correct Answer

Dmitry Bastron answered on October 9, 2019 11:37

Hi Chibin,

Here are a few notes from me:

  1. Not sure about data cache, but output cache can definitely be stored on Redis and invalidated via Kentico mechanics. Refer to MS article.
  2. When web farms disabled - sync between CMS and MVC not working. You change something in CMS and MVC does not receive dummy keys touched event.
  3. Widget controllers do not have their own output cache. Output cache dependencies there are request context specific. If you look at the ArticlesWidgetController.cs you'll see mOutputCacheDependencies.AddDependencyOnPages<Article>(); which means the following:
    • it creates dependency for output cache of the page where Articles widget placed
    • imagine Articles widget placed on page X
    • Article object changes
    • output cache of the page X will be invalidated because of Articles widget placed there

Hope it all makes sense.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Michal Samuhel answered on October 9, 2019 17:30

Hi Chibin,

I will add to Dmitry.

Our caching counts with in memory cache. You can customize CacheHelper to work with Redis cache and store data inside.

For MVC app cache, you just need to tell .NET to store cache data inside of Redis instead with configuration or as described in some articles.

If Redis client and output cache integration goes deep enough to influence HttpRuntime.Cache.Insert, you would not even need to customize mentioned handler, but I can not tell as I had not looked into Redis that deep.

1 votesVote for this answer Mark as a Correct answer

Chibin Zhang answered on October 14, 2019 02:51

Hi Dmitry,

Thanks for the reply. I'm clear with the widget caching now, but the mOutputCacheDependencies.AddDependencyOnPages<Article>(); in the ArticlesController url Articles/Show/{guid} action public ActionResult Show(Guid guid, string pageAlias) is putting the controller for a specific article with the all article dependency. Does that mean one article change will effect another article's cache?

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on October 14, 2019 10:52

Yes, the following code line:


will invalidate the cache when any of the articles will change. It makes sense for Index() action (as there are many displayed at the same time). But for the Show(..) action I'd have replaced it with specific article dependency by ID.

0 votesVote for this answer Mark as a Correct answer

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