locked
Shared Cache with OutputCache RRS feed

  • Question

  • Hi!

    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?

    Thanks,

    Laszlo

    Monday, July 16, 2012 11:31 AM

Answers

All replies

  • 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).


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marked as answer by Arwind - MSFT Monday, July 23, 2012 7:00 AM
    Tuesday, July 17, 2012 7:09 AM
  • How would you share the list of keys between instances?

    We use the shared cache so we don't have share the keys.

    Tuesday, July 17, 2012 8:33 AM
  • You can store the keys themselves in cache. For example:

    Key: Keys

    Value: A list of keys


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Wednesday, July 18, 2012 1:44 AM
  • 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.

    Wednesday, July 18, 2012 7:42 AM