title: How to programmatically clear outputcache for controller action method
body: <p>If the controller action has the OutputCache attribute specified on an action, is there any way to clear the output cache without having to restart IIS?</p>
  
  <pre><code>[OutputCache (Duration=3600,VaryByParam="param1;param2")]
  public string AjaxHtmlOutputMethod(string param1, string param2)
  {
    var someModel = SomeModel.Find( param1, param2 );
  
    //set up ViewData
    ...
  
    return RenderToString( "ViewName", someModel );
  }
  </code></pre>
  
  <p>I'm looking at using <code>HttpResponse.RemoveOutputCacheItem(string path)</code> to clear it, but I'm having trouble figuring out what the path should be to map it to the action method. I'm going to try again with the aspx page that is rendered by ViewName.</p>
  
  <p>Possibly I'll just manually insert the output of <code>RenderToString</code> into the <code>HttpContext.Cache</code> instead if I can't figure this one out. </p>
  
  <p><b>Update</b></p>
  
  <p>Please note that the OutputCache is VaryByParam, and testing out a hardcoded path "/controller/action" does not actually clear the outputcache, so it looks like it has to match "/controller/action/param1/param2".</p>
  
  <p>That means I'll probably have to revert to object level caching and manually cache the output for <code>RenderToString()</code> :(</p>