Episerver Output Cache - implementing












0















I am trying to follow some instructions I found online in order to implement output caching for episerver.



In my web.config I have set up the following:



   <caching>
<outputCache enableOutputCache="true">
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>


As a test, I selected StartPageController.cs and added the [ContentOutputCache] tag like so:



    [ContentOutputCache]
public class StartPageController : PageControllerBase<StartPage>
{
public ActionResult Index(StartPage currentPage)
{
var model = PageViewModel.Create(currentPage);

if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink))
{

var editHints = ViewData.GetEditHints<PageViewModel<StartPage>, StartPage>();
editHints.AddConnection(m => m.Layout.Logotype, p => p.SiteLogotype);
editHints.AddConnection(m => m.Layout.Footer, p => p.FooterBlock);
}

return View(model);
}
}
}


Then the instructions say:




At some point on a page load you need to add the following code:



public void SetResposneHeaders()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(2.0));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
}




Due to my limited knowledge of .NET, MVC etc.. this part confuses me as I am not sure in which file to place it and where? Does this go in StartPageController.cs? Or somewhere else?



Any pointers would be appreciated.



The instructions I am trying to follow are here.










share|improve this question























  • That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

    – Ted Nyberg
    Nov 21 '18 at 14:31













  • As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

    – PartisanEntity
    Nov 21 '18 at 16:05













  • not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

    – Lanorkin
    Nov 23 '18 at 9:35


















0















I am trying to follow some instructions I found online in order to implement output caching for episerver.



In my web.config I have set up the following:



   <caching>
<outputCache enableOutputCache="true">
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>


As a test, I selected StartPageController.cs and added the [ContentOutputCache] tag like so:



    [ContentOutputCache]
public class StartPageController : PageControllerBase<StartPage>
{
public ActionResult Index(StartPage currentPage)
{
var model = PageViewModel.Create(currentPage);

if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink))
{

var editHints = ViewData.GetEditHints<PageViewModel<StartPage>, StartPage>();
editHints.AddConnection(m => m.Layout.Logotype, p => p.SiteLogotype);
editHints.AddConnection(m => m.Layout.Footer, p => p.FooterBlock);
}

return View(model);
}
}
}


Then the instructions say:




At some point on a page load you need to add the following code:



public void SetResposneHeaders()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(2.0));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
}




Due to my limited knowledge of .NET, MVC etc.. this part confuses me as I am not sure in which file to place it and where? Does this go in StartPageController.cs? Or somewhere else?



Any pointers would be appreciated.



The instructions I am trying to follow are here.










share|improve this question























  • That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

    – Ted Nyberg
    Nov 21 '18 at 14:31













  • As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

    – PartisanEntity
    Nov 21 '18 at 16:05













  • not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

    – Lanorkin
    Nov 23 '18 at 9:35
















0












0








0








I am trying to follow some instructions I found online in order to implement output caching for episerver.



In my web.config I have set up the following:



   <caching>
<outputCache enableOutputCache="true">
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>


As a test, I selected StartPageController.cs and added the [ContentOutputCache] tag like so:



    [ContentOutputCache]
public class StartPageController : PageControllerBase<StartPage>
{
public ActionResult Index(StartPage currentPage)
{
var model = PageViewModel.Create(currentPage);

if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink))
{

var editHints = ViewData.GetEditHints<PageViewModel<StartPage>, StartPage>();
editHints.AddConnection(m => m.Layout.Logotype, p => p.SiteLogotype);
editHints.AddConnection(m => m.Layout.Footer, p => p.FooterBlock);
}

return View(model);
}
}
}


Then the instructions say:




At some point on a page load you need to add the following code:



public void SetResposneHeaders()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(2.0));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
}




Due to my limited knowledge of .NET, MVC etc.. this part confuses me as I am not sure in which file to place it and where? Does this go in StartPageController.cs? Or somewhere else?



Any pointers would be appreciated.



The instructions I am trying to follow are here.










share|improve this question














I am trying to follow some instructions I found online in order to implement output caching for episerver.



In my web.config I have set up the following:



   <caching>
<outputCache enableOutputCache="true">
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>


As a test, I selected StartPageController.cs and added the [ContentOutputCache] tag like so:



    [ContentOutputCache]
public class StartPageController : PageControllerBase<StartPage>
{
public ActionResult Index(StartPage currentPage)
{
var model = PageViewModel.Create(currentPage);

if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink))
{

var editHints = ViewData.GetEditHints<PageViewModel<StartPage>, StartPage>();
editHints.AddConnection(m => m.Layout.Logotype, p => p.SiteLogotype);
editHints.AddConnection(m => m.Layout.Footer, p => p.FooterBlock);
}

return View(model);
}
}
}


Then the instructions say:




At some point on a page load you need to add the following code:



public void SetResposneHeaders()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(2.0));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
}




Due to my limited knowledge of .NET, MVC etc.. this part confuses me as I am not sure in which file to place it and where? Does this go in StartPageController.cs? Or somewhere else?



Any pointers would be appreciated.



The instructions I am trying to follow are here.







asp.net-mvc outputcache episerver






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 9:41









PartisanEntityPartisanEntity

3213923




3213923













  • That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

    – Ted Nyberg
    Nov 21 '18 at 14:31













  • As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

    – PartisanEntity
    Nov 21 '18 at 16:05













  • not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

    – Lanorkin
    Nov 23 '18 at 9:35





















  • That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

    – Ted Nyberg
    Nov 21 '18 at 14:31













  • As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

    – PartisanEntity
    Nov 21 '18 at 16:05













  • not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

    – Lanorkin
    Nov 23 '18 at 9:35



















That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

– Ted Nyberg
Nov 21 '18 at 14:31







That last part shouldn't be necessary. Have you checked if it works without it? Note that you shouldn't be logged in, as the output cache will be disabled for logged-in users. Also, check the cache settings attributes of the <applicationSettings> element in web.config.

– Ted Nyberg
Nov 21 '18 at 14:31















As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

– PartisanEntity
Nov 21 '18 at 16:05







As far as I can tell it is not working. When I check the headers in the browser then cache-control is set to private. Here is the entry from web.config: <applicationSettings httpCacheability="Public" pageValidateTemplate="false" uiShowGlobalizationUserInterface="true" uiUrl="~/EPiServer/CMS/" urlRebaseKind="ToRootRelative" uiEditorCssPaths="~/Static/css/Editor.css" uiSafeHtmlTags="b,i,u,br,em,strong,p,a,img,ol,ul,li" />

– PartisanEntity
Nov 21 '18 at 16:05















not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

– Lanorkin
Nov 23 '18 at 9:35







not answering your question specifically, but - output cache and browser cache are different things; output cache means server will not render it again (i.e. create controller, load page data etc); browser cache means that browser (for example) will not request server at all until cache expires. That are different things used for different purposes, you need to carefully consider what you want. Say, output cache in episerver guarantees that if a page has been changed, then user will see updates; with browser cache, that is not true.

– Lanorkin
Nov 23 '18 at 9:35














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409124%2fepiserver-output-cache-implementing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409124%2fepiserver-output-cache-implementing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith