Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Cannot use ContentOutputCache on a block controller or Page controller

Vote:
 

I have been trying to add ContentOutputCache to a block controller so that the blocks can have caching enabled. I put the attribute above the action of Index to apply it to the action so that whenever the block is used it will cache the details inside. When running the site and going to the page, I get the following error:

ContentOutputCacheAttribute should not be used on child actions.

I have tried to apply the output cache to the Alloy Demo and I also get the same error. Below is an example bit of code on what I am trying to do.

public class ContactBlockController : BlockController
{
        [ContentOutputCache]
        public override ActionResult Index(ContactBlock currentBlock)
        {

        }
}

I have also added the settings into Web.Config to enable the caching as well. 

After some more testing, I also tried it on the Page Controller. I made a property that renders the current DateTime to the view and disbled debug mode and ran the website in release mode. The caching still does not work on pages either.

Any help would be appreciated. 

#181613
Edited, Aug 25, 2017 12:03
Vote:
 

Hi Steven,

ContentOutputCache has several criteria:

  1. Cannot be used for child actions.
  2. The current user must not be logged in -> anonymous user
  3. The page has to be published
  4. httpCacheExpiration has to have a value greater than 0.

You can configure httpCacheExpiration in web.config under configuration/episerver/applicationSettings. Alloy demo doesn't come with predefined httpCacheExpiration

#181620
Edited, Aug 25, 2017 13:06
Vote:
 

Hello Dejan,

Thanks for the quick response. Completely overlooked the Logged In/ Logged Out scenerio. Have tried it and it works as expected now!

Thanks for for your help

#181642
Aug 25, 2017 14:11
Vote:
 

@Dejan Caric Is there a way to disable this for so certain blocks are updated. Main example is we use a C# Twitter library and the block does not update when the Caching is on for the page it is contained in.

Thanks in advance

#181648
Edited, Aug 25, 2017 17:00
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.