代码之家  ›  专栏  ›  技术社区  ›  Lobstrosity

ASP.NET MVC:从其他操作中清除操作的缓存

  •  2
  • Lobstrosity  · 技术社区  · 16 年前

    是否可以从另一个操作中清除一个操作的缓存?

    假设我的索引操作列出了所有的小部件。有很多小部件,但是新的小部件并不是经常创建的。所以我想无限期地缓存我的索引操作,但在成功创建后强制它呈现。

    public class WidgetController : Controller
    {
        [OutputCache(Duration = int.MaxValue, VaryByParam = "none")]
        public ActionResult Index()
        {
            return View(Widget.AllWidgets);
        }
    
        public ActionResult Create()
        {
            return View();
        }
    
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(string name)
        {
            Widget widget = new Widget(name);
    
            // Can I clear Index's cache at this point?
            // ClearCache("Index");
    
            return View(widget);
        }
    }
    
    3 回复  |  直到 16 年前
        1
  •  4
  •   takepara    16 年前

    httpResponse.RemoveOutputCacheItem?

        2
  •  2
  •   Chris Shaffer    16 年前

    每当添加新的小部件时,使用varybycustom属性使缓存过期。

        3
  •  0
  •   Darin Dimitrov    16 年前

    如果你打电话给 Create 操作不会命中缓存,因为您只是在呈现视图,而不是重定向到 Index 其输出已缓存的操作。