There is actually an easier and cheaper method for avoiding Drupal's page cache that is used by newer versions of CacheExclude. The cleverness is that we put it in hook_init(). It doesn't get run on cached pages so we don't add any overhead to those pages. Then, if its a cart page, we set the global conf variable for caching to 0 so later in the page request when Drupal checks if it should write to page cache it see's caching is disabled(only for this request). So nothing is written and the page isn't cached.

I've been running this on my live site for a number of months and have been using this trick for years. Its pretty solid but leaving NR so someone can look over it if they want.

Comments

neclimdul’s picture

StatusFileSize
new1.24 KB

Posting patches late friday is apparently not working for me. Here's the patch.

longwave’s picture

Looks like the drupal_match_path() call doesn't match just "cart", is this correct?

neclimdul’s picture

That's correct. It matches anything under cart. This maybe a little overkill but it was easier that 4 calls to match the previous 4 pages.
$pages = array('cart', 'cart/checkout', 'cart/checkout/review', 'cart/checkout/complete');

Also, it personally made more sense as anything under cart/ would be linked to the cart and dynamic so should avoid caching. Its easy enough to convert to the 4 explicit matches though.

longwave’s picture

No, what I meant was doesn't drupal_match_path($_GET['q'], 'cart/*') miss the main shopping cart page at /cart ? (as it doesn't have a trailing slash) - perhaps it should be drupal_match_path($_GET['q'], 'cart\ncart/*') instead?

neclimdul’s picture

oh interesting, I'll check

tr’s picture

Status: Needs review » Postponed (maintainer needs more info)

Changed status to reflect #4 and #5.

longwave’s picture

Seems like it would be simpler and more readable to just use if (arg(0) == 'cart') { ... } here.

neclimdul’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.17 KB

I generally loath to use arg() but I can't argue that it seems a good fit here. Updated patch.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.16 KB

Rerolled around some whitespace changes.

Been running happily for 6 months now so... since maintainer response was positive and the code is well tested in CacheExclude and the only functionality change was maintainer requested I'm going to go ahead and mark this RTBC. Sorry if I'm overstepping my bounds there.

longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Not ported to 7.x because #1285818: Remove uc_cart_exit() and cache-safe cart block should solve this instead.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.