OutputCache with dynamic widget on all pages = no-go?

Topics: Core, General
Sep 30, 2014 at 9:48 AM
We have developed a widget to cope with the EU cookie law. The user sees this message on all pages until he/she clicks 'I agree'.

The driver of this widget decides whether the message needs to be shown (obviously based on a cookie).

However, if OutputCache is enabled, one of both versions is cached. This means it's possible for another user to see the message even if he/she already clicked 'I agree', or vice versa.

Because this widget is shown on all pages, the only solution is to disable the OutputCache module completely, is this correct?

Another example is a Cart widget. This widget shows a summary of the cart (total price, number of artikels) on all pages. Again, with OutputCache enabled, users see an outdated version of the cart and/or carts of other users.

A solution for this would be to return a generic page to the client (one that can be cached) and handle the dynamic stuff in the browser via a second AJAX call and update the DOM accordingly. However, this would increase the number of request.

Any opinions on this issue? Would you move stuff to the client? Or just disable the OutputCache module altogether?
Sep 30, 2014 at 11:13 AM
We have moved same functionality to client. So, it is not affected by OutputCache.
Another approach maybe is: http://gallery.orchardproject.net/List/Modules/Orchard.Module.IDeliverable.AjaxWidget

No option to turn off OutputCache.
Sep 30, 2014 at 5:00 PM
I think using a client side generated request is the solution here.
Sep 30, 2014 at 5:30 PM
Yes, of course, output cache caches the output. You'd need doughnut caching.

Look at the implementation of the shopping cart in Nwazet.Commerce: it's handled with script, as it should. In the case of a shopping cart, there are more reasons than caching: persistent storage on the client of the contents of the cart is another one. Having an extra request is not a problem, it's a necessity, like it is for stylesheets, scripts, and images.
Sep 30, 2014 at 6:50 PM
An easy way to exclude any widget from output caching is to "ajaxify" widgets. IDeliverable.Widgets provides an AjaxifyPart that you can attach to any content type (including widget types).
Sep 30, 2014 at 7:14 PM
Thanks, all.

There's still something that's not clear to me...

A default Orchard installation has OutputCache enabled and had logon capabilities. If the first visit to the homepage is me, already authenticated as admin, the page shows 'Welcome, admin!' together with 'Sign Out' and 'Dashboard' links. Is this version cached? Still another (unauthenticated) user does not see that same footer. What's preventing this?

And what about page with AntiForgery forms?
Sep 30, 2014 at 7:58 PM
Output Cache is not enabled for authedicanted requests.
Sep 30, 2014 at 8:11 PM
Right, that makes sense!!

A small rewrite of several widgets just made it to the top of my todo list :)