Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

OutputCache Implementation Help

$
0
0

Hi there,

Trying to set up outputcache but failing so far.

I have ensured that I have the following in my web.config:

<caching>
    <outputcache enableoutputcache="true"/>
    <outputcachesettings>
        <outputcacheprofiles>
            <add name="ClientResourceCache" enabled="true" duration="3600" varybyparam="*" varybycontentencoding="gzip;deflate" />
        </outputcacheprofiles>  
    </outputcachesettings>      
</caching>

And:

<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">
</applicationsettings>

Next, I added [ContentOutputCache] to my StartPageController.cs like so:

[ContentOutputCache]
public class StartPageController : PageControllerBase
{
public ActionResult Index(StartPage currentPage)

{

var model = PageViewModel.Create(currentPage);

if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink)) // Check if it is the StartPage or just a page of the StartPage type.
{
//Connect the view models logotype property to the start page's to make it editable
var editHints = ViewData.GetEditHints, StartPage>();
editHints.AddConnection(m => m.Layout.Logotype, p => p.SiteLogotype);
editHints.AddConnection(m => m.Layout.Footer, p => p.FooterBlock);
}

return View(model);
}
}

But it does not appear to be working. I have ensured that I am not logged in during testing. But when looking at the headers in the browser I see under cache-control: private.

In the article it mentions:

The next part of the process is to enable the response headers on your page.  If you don't do this you will see a no-cache set in your HTML requests response header.  To do this is pretty simple.  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);
        }

But I am unsure where to place this bit, and how to call it.


Viewing all articles
Browse latest Browse all 9076

Trending Articles