0

I want to run a consol app that calls a website on all outputcacheing pages so that all the cached paged will be cached for the user. When using the browser the page caches correctly but I want to be able to run a function that caches all the pages for the users.

Im using new System.Net.WebClient().DownloadString("http://url"); but the pages wont cache when using this call.

Cacheing attribute

[ChildActionOutputCache(("CacheAll"), Location = OutputCacheLocation.Server)]

Attribute Function

public class ChildActionOutputCacheAttribute : OutputCacheAttribute
    {
        public ChildActionOutputCacheAttribute(string cacheProfile)
        {
            var settings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
            var profile = settings.OutputCacheProfiles[cacheProfile];
            Duration = profile.Duration;
            VaryByParam = profile.VaryByParam;
            VaryByCustom = profile.VaryByCustom;
        }
    }

web.config properties for attribute

 <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CacheAll" 
               duration="43200"
               location="Server"
               varyByParam="*"/>
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
user473104
  • 301
  • 2
  • 6
  • 17

1 Answers1

0

I know this is an old question, but for others googling why Output Cache doesn't work for their requests made by their Console application - the answer is cookies.

The request you are making has no cookies, the response from the server has new cookies - so it doesn't cache the output.

Use the code in this answer to make your request and everything will cache OK: https://stackoverflow.com/a/3892075

What I had to do was make a request to my application's home page. This got the session sorted, with session cookie returned. Those cookies were then added to subsequent requests (to the pages I wanted cached) and everything worked as expected.

Community
  • 1
  • 1
Ronan
  • 1