0

I have a MVC application which is running seamlessly. Now I want to improve the caching a little bit. I was trying to use the OutputCache attribute from the System.Web.Mvc namespace, but no metter which value I chose, the header was always either public or private. Is it possible to set caching to private AND public using this attribute?

Tomas Walek
  • 2,516
  • 2
  • 23
  • 37

1 Answers1

0

There is no way to set an Output cache to be both private and public.

Digging into the source of Page.cs for example we find the following. NB there is no option on 'cacheability' for both of these they are implemented as alternatives to each other.

  switch (outputCacheLocation)
  {
    case OutputCacheLocation.Any:
      cacheability = HttpCacheability.Public;
      break;
    case OutputCacheLocation.Client:
      cacheability = HttpCacheability.Private;
      break;
    case OutputCacheLocation.Downstream:
      cacheability = HttpCacheability.Public;
      cache.SetNoServerCaching();
      break;
    case OutputCacheLocation.Server:
      cacheability = HttpCacheability.Server;
      break;
    case OutputCacheLocation.None:
      cacheability = HttpCacheability.NoCache;
      break;
    case OutputCacheLocation.ServerAndClient:
      cacheability = HttpCacheability.ServerAndPrivate;
      break;
    default:
      throw new ArgumentOutOfRangeException("cacheSettings", System.Web.SR.GetString("Invalid_cache_settings_location"));
  }

You can read more about the HttpCacheability enum here http://msdn.microsoft.com/en-us/library/system.web.httpcacheability(v=vs.110).aspx

NB doing this doesn't even make sense to me but I might be missing something.

Dave Walker
  • 3,498
  • 1
  • 24
  • 25