16. července 2012 11:31
I try to use Azure Shared Cache with MVC's Outputcache, however I run into several pitfalls.
First of all, it does not work properly wih the Authorize attribute. On Stack Overflow I found several discussion about this question, but no proper answer.
The real problem is invalidation: using the standard MVC cache, CacheDependency is used to create a second cache item, which has a known key so it can invalidated by me. This way when I invalidate my cache item from code, the origional MVC cached content is invalidated as well due to the dependency.
Shared cache does not support cache dependency. So how can I invalidate an item? I can invalidate a page, but this way I cannot cache user dependent data.
I have tryed to create the cache key (for invalidation) the same way as the OutputCache does, but it uses to many internal and private methods, thus I would need the whole source code of the DLL. (This way by implementing an own cache provider that internally uses the azure cache provider I could invalidate by myself.)
Another solution is to create an own attribute implementing the ActionFilterAttribute, and do the same thing as the OutputCache attribute. But I run into the same problem as above. (that I need the whole DLL)
So the real problem is that the OutputCache provider can be custom, but there is no way to override the Key Generation so I could use my own keys depending by the user's Id, and also which can be invalidated by myself from code.
Has anybody run into this problem? What is the solution for this?
17. července 2012 7:09Moderátor
Since currently shared cache does not support dependency, you cannot use it. You can submit a feature request on http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting.
One workaround is to manually keep a list of cached item keys. When you want to invalidate the cached item, you remove it from cache (using the Remove method).
- Označen jako odpověď Arwind - MSFTModerator 23. července 2012 7:00
17. července 2012 8:33
How would you share the list of keys between instances?
We use the shared cache so we don't have share the keys.
18. července 2012 1:44Moderátor
18. července 2012 7:42
Thank you for your idea, it sounds viable, however you need some kind of optimistic/pessimistic concurrency handling for the value. I give a try to this solution, see the results, and give a feedback soon.