Howdy!
Using debug_backtrace() I was able to find out that uc_views.views.inc gets called no matter what. (That in itself is news to me, but not surprising.)
Anyway, this bit of code:
/**
* Implementation of hook_views_query_substitutions().
*/
function uc_views_views_query_substitutions($view) {
return array('***CURRENT_CART_ID***' => uc_cart_get_id());
}
calls uc_cart_get_id() which, in its default state, creates a new session cookie ("uc_cart_id") which, when using a reverse proxy cache like Varnish, does not allow pages to be cached at that point.
The quick and easy solution is to throw FALSE into uc_cart_get_id so that a cart is not created if one is not already found. I've tested this, and it seems to work fine, but wanted to get others' feedback and input on this. I can write a patch so you can test it, if you like, but this is pretty quick and dirty. The new function looks thusly:
/**
* Implementation of hook_views_query_substitutions().
*/
function uc_views_views_query_substitutions($view) {
return array('***CURRENT_CART_ID***' => uc_cart_get_id(FALSE));
}
On our testing server this change allowed Varnish to cache and serve the pages (until of course an item is added to the cart). Thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | uc_views-cart_session-1037834-7.patch | 505 bytes | achton |
Comments
Comment #1
longwaveThanks for finding that, never realised that would cause a problem! However, when there's an anonymous user that has no cart, we probably shouldn't try FALSE as the cart id just in case. How about this?
Comment #2
torgospizzaTested your solution and it seems to work just fine. Thanks!
Comment #3
longwaveCommitted.
Comment #4
torgospizzaWoot! Still getting X-Cache: HIT on my end, so things look great. Thanks!
Comment #6
vacilando commentedI spent several hours today trying to find out why Varnish does not cache my anonymous pages. Found that uc_cart_id was set in the session cookie.
Finally found this post, installed the dev version, and the session cookie is finally gone. Thanks!
Could you please publish a new stable version of the module so that more people update their modules?
Comment #7
achtonHere is a proper patch against current stable version (e.g. for Drush Make).
Comment #8
burningdog commentedThanks - am so glad this has been fixed! I've patched my 6.x-3.1 uc_views with the patch at #7 and now sessions are no longer being set by ubercart on urls that load views.
Can this patch please make it into the stable release?
Comment #9
longwaveThis is already in -dev and will be in the forthcoming 6.x-3.2.