Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a cache item #9

Open
jhoefnagels opened this issue Dec 2, 2011 · 1 comment
Open

Remove a cache item #9

jhoefnagels opened this issue Dec 2, 2011 · 1 comment

Comments

@jhoefnagels
Copy link

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.

@janjongboom
Copy link
Owner

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants