Gib*_*boK 38 c# asp.net-mvc caching asp.net-mvc-3
使用ASP.Net MVC 3我有一个控制器,其输出正在使用属性进行缓存 [OutputCache]
[OutputCache]
public controllerA(){}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以通过调用另一个控制器使特定控制器的缓存数据(SERVER CACHE)或通常所有缓存数据无效
public controllerB(){} // Calling this invalidates the cache
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 57
你可以使用这个RemoveOutputCacheItem方法.
以下是如何使用它的示例:
public class HomeController : Controller
{
[OutputCache(Duration = 60, Location = OutputCacheLocation.Server)]
public ActionResult Index()
{
return Content(DateTime.Now.ToLongTimeString());
}
public ActionResult InvalidateCacheForIndexAction()
{
string path = Url.Action("index");
Response.RemoveOutputCacheItem(path);
return Content("cache invalidated, you could now go back to the index action");
}
}
Run Code Online (Sandbox Code Playgroud)
索引操作响应在服务器上缓存1分钟.如果您点击该InvalidateCacheForIndexAction操作,它将使Index操作的缓存失效.目前无法使整个缓存无效,您应该根据缓存操作(而非控制器)执行此操作,因为该RemoveOutputCacheItem方法需要缓存的服务器端脚本的URL.
| 归档时间: |
|
| 查看次数: |
12198 次 |
| 最近记录: |