Try our conversational search powered by Generative AI!

Caching GetVaryByCustomString for CMS 12



We are referring solution given in this link for implementing VaryByCustom caching. But it is not going through this method.

Can anyone suggest on what might be missing for this to work or help on how can this implemented in CMS 12 to work.



May 25, 2023 5:04

Hi Deepa,

I had a look through the blog post and I just wanted to check you have done the following:

  1. Installed the nuget package.
  2. Configured it as per the readme .
  3. Add the Attribute to a controller and tested '[ContentOutputCache(Duration = 86400)]'.

If this is all working then I think a good place to start looking is the order of the service registration.

From the first blog you should have added:


To then use the custom implementation of 'IOutputCacheVaryByCustomService' you would need to call the service registration after this:

services.AddTransient<IOutputCacheVaryByCustomService, OuputCacheVaryByCustomService>();

Does this all look like your code?

You can see the example startup.cs here


Edited, May 25, 2023 8:41

Yes followed all these steps as mentioned here. 

May 25, 2023 9:13

I believe no content cache will work unless you set the content cache properties in appsettings, see


  "EPiServer": {
    "CMS": {
      "Content": {
        "VersionCacheSlidingExpiration": "0:0:10",
        "ContentCacheSlidingExpiration": "0:0:10"
May 25, 2023 10:59


Yes added this configuration in appsettings.json file. It will not fire the GetVaryByCustomString() method from service.

Do we need to call this method explicitly apart from adding this line [ContentOutputCache(Duration = 86400, VaryByCustom="visitorgroups")] for controller action method?



May 30, 2023 9:09
Paul McGann (Netcel) - May 31, 2023 9:55
Hi Deepa,

I have created a simple demo site with this working.

You can find this here

Just to note, on the first load f the site the startpage will not hit the implementation, however if you browse the site then go back to the startpage it will hit it.

Deepa Puranik - May 31, 2023 16:00
Hello Paul,

Thank you so much for all help.
I did configure it the way it is there in this repo. Thank you again.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.