title: Controlling ASP.NET output cache memory usage
body: <p>I would like to use output caching with WCF Data Services and although there's nothing specifically built in to support caching, there is an OnStartProcessingRequest method that allows me to hook in and set the cacheability of the request using normal ASP.NET mechanisms.</p>
  
  <p>But I am worried about the worker process getting recycled due to excessive memory consumption if large responses are cached. Is there a way to specify an upper limit for the ASP.NET output cache so that if this limit is exceeded, items in the cache will be discarded?</p>
  
  <p>I've seen the <a href="http://msdn.microsoft.com/en-us/library/ms228248(v=VS.100).aspx" rel="nofollow noreferrer">caching</a> configuration settings but I get the impression from the documentation that this is for explicit caching via the Cache object since there is a separate <a href="http://msdn.microsoft.com/en-us/library/ms228270(v=VS.100).aspx" rel="nofollow noreferrer">outputCacheSettings</a> which has no memory-related attributes.</p>
  
  <p>Here's a code snippet from <a href="http://www.hanselman.com/blog/CommentView.aspx?guid=d7e873d4-8e68-4d8d-883c-093ed2acc791" rel="nofollow noreferrer">Scott Hanselman's post</a> that shows how I'm setting the cacheability of the request.</p>
  
  <pre><code>protected override void OnStartProcessingRequest(ProcessRequestArgs args)
  {
      base.OnStartProcessingRequest(args);
      //Cache for a minute based on querystring
      HttpContext context = HttpContext.Current;
      HttpCachePolicy c = HttpContext.Current.Response.Cache;
      c.SetCacheability(HttpCacheability.ServerAndPrivate);
      c.SetExpires(HttpContext.Current.Timestamp.AddSeconds(60));
      c.VaryByHeaders["Accept"] = true;
      c.VaryByHeaders["Accept-Charset"] = true;
      c.VaryByHeaders["Accept-Encoding"] = true;
      c.VaryByParams["*"] = true;
  }
  </code></pre>