Remove a cache item
jhoefnagels opened this issue · comments
I would like to remove a page from the output cache from a controller after a db update but I could not find a way to make this work. The cache key is hard to construct outside the controller that contains the action filter that added the cache item.
Let's see if I can find an elegant way to invalidate pages. For now a quick intro on the cache key. It's in MothAction.cs. The cache key consists of min. 2 items:
- Controller name
- Action name
- Hashcodes of Parameter values
The action HomeController.Index(int pageId, string something)
where pageId = 3
and something = "hi"
will be constructed as:
var items = new List<string>();
items.Add("Home");
items.Add("Index");
items.Add(3.GetHashCode());
items.Add("hi".GetHashCode());
var key = string.Join("|", items.ToArray());
You can delete this item from the cache via:
new AspNetCacheProvider().Store(key, null, new TimeSpan(0, 0, 1));