4

I have html fragments in a partial view that uses the output cache like so

 <cache vary-by="@Util.SomeID" expires-after="@TimeSpan.FromHours(1)">
     <div>some content</div>
 </cache>

In the event that I need the content to be updated before the expiration of the cache, how do I go about busting the cache for that particular fragment (or the entire cache, if necessary) ?

I'm using ASP.NET 5 and MVC 6..

Thanks!

2

2 Answers 2

1

The IMemoryCache interface doesn't have a method to clear the cache. Otherwise you could inject IMemoryCache to your controller or where ever you need it and call the method.

I suggest to post a feature request on the aspnet caching repository or use a different cache mechanism.

I'm working on extending CacheManager to be usable in MVC Core as memory or distributed cache which then will have a lot more functionality than the build in, pretty simple, memory cache...

Sign up to request clarification or add additional context in comments.

Comments

0

The ASP.NET team has confirmed that it's not possible to directly clear cache items today. The workaround suggested is to use a "version" variable as part of the vary-by cache parameter.

That will not actually clear out the existing value, but the new value will be rendered. The old value will eventually be cleaned up as it expires.

More details at https://github.com/aspnet/Mvc/issues/4117#issuecomment-187298466

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.