1

I have implemented the browser caching on the Sitecore item as follows.

  public class BrowserCaching : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {
            Item currentItem;

            Assert.ArgumentNotNull(args, "args");
            Profiler.StartOperation("Update browser caching headers.");
            var currentContext = HttpContext.Current;
            currentItem = global::Sitecore.Context.Item;

            if (currentContext == null)
                return;

            if (currentItem.TemplateID.ToString() == "{D00CA443-2122-555C-A72C-4541E3C733FF}")
            {
                SetCacheHeaders(currentItem, currentContext);
            }
            Profiler.EndOperation();
        }

        private static void SetCacheHeaders(Item item, HttpContext currentContext)
        {
            currentContext.Response.Cache.SetCacheability(HttpCacheability.Public);
            var ts = new TimeSpan(0, Convert.ToInt32(30), 0);
            currentContext.Response.Cache.SetMaxAge(ts);
            currentContext.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
            var date = item.Statistics.Updated;
            if (date > DateTime.Now)
            {
                date = DateTime.Now;
            }
            currentContext.Response.Cache.SetLastModified(date);
            currentContext.Response.Cache.SetETag(item.Statistics.Revision);
        }
    }

The Cache MaxAge is 30 mins. Expires is 1 year. The headers for the first request and Page refresh looks like this.

First request

enter image description here

Page refresh

enter image description here

The header seems to set the cache control headers in the Response headers but the page is not getting cached. On every refresh (hitting the enter button on address bar to refresh the page), the status is 200. I am using Chrome developer tool and also checked the Disable cache checkbox is unchecked. Also not using the incognito mode.

I have checked Chrome/Firefox and IE and the page status is always 200. The page is not getting cached. Seems like no-cache=“Set-Cookie” is causing this and here is the similar question What is setting no-cache="Set-Cookie".

If i remove this set-cookie from the header then will it cause any problems to storing the contact detail in analytics?. How can I remove this line from the header. Is this causing page not to be cached?. Please any help would be appreciated

Thanks in advance

1
0

Chrome can ignore Cache-Control, Max-age and Expires headers. (I suppose that you uses Chrome by your screenshot)

Modern browsers are too smart that even if you send them cache headers, they can ignore them in next cases:

I suggest you to verify if your code works by debugging code(check if it is called) and reviewing IIS logs, because your cache headers look ok.

P.S. Think twice before starting using caching in browser on page level, you will lose some Sitecore features, for example personalization.