0

I have a very data intensive operation in my MVC3 application. To get some performance gains, I have cached the result as follows:

[OutputCache(Duration=60,VaryByParam="none")]
    public ActionResult Index(string server, string database)
{ //get+display a list of objects
}

This works well. But I want to clear the cache if certain actions happen like an Edit or Create. To clear the cache I am doing this

var urlToRemove = Url.Action("HtmlOutputMethod", "Controller");
Response.RemoveOutputCacheItem(urlToRemove);

Following: How to programmatically clear outputcache for controller action method

BUT when I try to cache the Action on the Server so that the cache deletion actually works like this:

[OutputCache(Location="Server", Duration=60,VaryByParam="none")]
    public ActionResult Index(string server, string database)

I get this error:

Cannot implicitly convert type 'string' to 'System.Web.UI.OutputCacheLocation'

Is this deprecated in MVC3 or am I missing an assembly? I see this used all over the place but it won't compile on my machine.

Community
  • 1
  • 1
Rondel
  • 4,811
  • 11
  • 41
  • 67

1 Answers1

1

As it says use OutputCacheLocation:

[OutputCache(Location=OutputCacheLocation.Server, Duration=60,VaryByParam="none")]
public ActionResult Index(string server, string database)

And at usings add:

using System.Web.UI;
Gumowy Kaczak
  • 1,457
  • 2
  • 16
  • 28