I'm trying to prevent output cached page from being ejected from my asp.net output cache unless another one can replace it. In other words, if a page has expired (based on Duration property of OutputCache profile开发者_开发问答) but accessing the page now results in an exception, I just want to serve the old, outdated page. I was hoping the custom cache providers in ASP.NET 4 would help my situation but they don't get far enough up the pipeline.
Here's what I know:
- System.Web.Caching.OutputCache is really hard to read through
- A custom cache provider hooks in after all dependencies and is fed a CachedVary object.
- The utcExpiry date passed into the custom cache provider's Add and Set methods is just DateTime.Max
- The actual expiration of the cache item happens higher up in the pipeline
- Even for expired items, the custom cache provider's Get method is still called. It returns the cached CachedVary object and then my controller's action method is called. After this, the Add method is called with the CachedVary object and Set method is passed an actual cached page data object.
Can someone with more experience hacking outputcache steer my in a direction here? Can I accomplish what I'm looking for with ASP.NET outputcache? Must I roll my own?
i ended up blogging about how i accomplished this here: http://statichippo.com/blog/archive/2011/09/25/graceful-degradation-via-asp-net-outputcacheprovider.aspx
精彩评论