简体   繁体   中英

MVC3 clearing cached actionResult from Controller issue

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM