Comments

It doesn't seem so: the initial cart contents is sent along with the initial page (and is thus also in the page cache, with the same problems as before), the AJAX is only used to update the cart once you press an Add to cart button.

A possible solution here would be to always send an empty (invisible) cart block to anonymous users, and update it with the actual content (bypassing the original cart block's i-don't-like-the-page-cache override so you don't just get the "click here to view your cart" message) through the AJAX call directly on page load.

Is there any working solution to this issue? - i have looked around on all the issue queues and documentation but seem to be going around in circles. Is it worth trying the dev version of this module? Anonymous user carts are necessary and am really trying to avoid turning off page caching as it makes the site a LOT slower.

But unfortunately it seems there is no other way - strange as it was suggested that this module was an alternative solution.

Just to start things going I attached a very crude patch that does sort of what we'd need.
- Disable the cache checking in ubercart/uc_cart/uc_cart.module:uc_cart_block('view'), otherwise we'd never get anything other than the cache-safe "click here to view your cart" out of it.
- Reload the cache block content through AJAX immediately on page load. This updates the cart block contents to that for the current (anonymous or other) user.

Still to do:
- The cart contents sent with the complete page (and cached) now again show the cart contents for the wrong user (since the check in uc_cart_block('view') was removed). It's overwritten immediately by the AJAX stuff, unless JavaScript is disabled or the call fails. What should be done is that the initial page contains the safe version, while the load through AJAX gets the "unsafe" (actual) content. This might need an extra argument to uc_cart_block('view') or something...
- Some stuff to get the collapsible cart block back, and to remember the collapsed state so it behaves just like the normal cart block.
- When the cart block is empty, the AJAX callback can set the block contents to empty, but this doesn't completely hide the block (some borders and white space remain), so a higher up would need to be hidden.

The first point will require a change in Ubercart core (unless we duplicate all of uc_cart_block('view') by calling and formatting uc_cart_get_contents() ourselves...).
The other two points are not that bad, they can probably be done in jquery.ajax.cart.js without too much difficulty.

1. There is a short lag between when the page loads and when the ajax call is made to update the cart. Therefore, the cart block flashes old, then new content. Is there anyway to avoid this?
2. The ajax call only seems to happen on my catalog/ pages. On all other pages, the cart block doesn't update. Did I do something wrong? Or is this to be expected?

as douglas mentioned above, this only works on certain pages. i don't user the catalog pages, but i noticed it works on product page, doesn't on others.

I tried manually calling jquery.ajax.cart.js from page.tp, but that didn't help.
tried using snippets of code for calling jQuery.getJSON( Drupal.settings.basePath + 'cart/ajax/update',{},updateAjaxCart);
but can't get it working...
I wonder what else must happen for this to function on all pages...

Since I don't really know how to replicate this "anonymous ghost cart" bug, could someone please explain in plain english if/how I can resolve this problem using uc_ajax_cart.

I noticed there's a bunch of options related to caching in the block settings, but I'm unclear which I should be setting to resolve the issue, or if it can even currently be fixed with -rc9. I couldn't find any documentation on this.

Are these options here to help?Rebuild cart cache.
Rebuild cart cache on every ajax call.

Clear cart cache on every ajax call.
With this option enabled, cart content is rebuilded every request.

<?phpfunction mytheme_uc_cart_block_summary($item_count, $item_text, $total, $summary_links) {// We have to do this to make sure that jquery.ajax.cart.js is loaded each time the cart is.if(module_exists("uc_ajax_cart")) {_uc_ajax_cart_load_res(); }}?>

I've made a bunch of other changes in uc_ajax_cart, but I believe this is all that's needed to get your anonymous cache loading on every page. This also avoids the uc_cart.module core modification from patch #6

EDIT: This solution requires that you do not check "hide block when cart is empty"

It could be me, but why is uc_cart block cached with the page? Doesn't page caching mean ontly the $content var is cached? Or the whole rendering of page.tpl.php? If the latter, why does D6 have a separate "block cache" anyway??

Page cache is for the whole page. Block cache is useful when page cache is not used, i.e. for logged in users or when page cache is turned off completely in the settings.

@j0rd: you said you could do it without changing uc_cart.module, but how did you get to the actual cart contents? I thought that with the page cache turned on (and for anonymous users), uc_cart_block('view') would only give you the safe "click here to view your cart" version...

j0rd: Hello, is this solution really working? I tried it and all it did was that the bottom part of cart (summary and links to cart and checkout, or that link in anonymous status) stopped showing. Is this supposed to fix the anonymous caching problem, or did I misunderstood that?

Proposition be Wimh in #1 post seems to me like perfect solution. Anybody working on such thing?

AJAX/jQuery added to every page. (cached with every page, standard code)

It looks for the existing, standard anonymous Cart block that is cache-safe but feature poor. (no changes or patches to the rest of Ubercart so far)

It tries to AJAX replace it with the full, up to date, sexy and uncached version once the page loads.

Profit!

This way, those without JS still get the safe version already in running Ubercart, but everyone else gets the real deal and we can still do page caching whilst keeping things pretty simple.

We really need this if Ubercart has a chance of being scalable or responsive in shared hosting environments. We need it doubly to get powerful cache modules like Boost, AuthCache and others working properly. Oh and there's Varnish and similar to think about, too.

I'd be glad to help out with this... Should this be a release blocker for UC2.0?

Ive made some progress in D5, but nothing more than a workaround. I use boost for static caching, dbs page cache = off. I wrote a tiny module that simply invokes the cart and spits it out as a JS variable like this:

Not working for me, Ubercart 2.2 and uc_ajax_cart 6.2-beta2 and Drupal 6.16. I always see "View your shopping cart."

Is there still not proper solution for this? I think it's kind of a big deal and Ubercart should really implement something directly. Or there should be a stand alone module which simply fixes this bug. I don't know of a single shopping cart, which doesn't display at least the amount of total of the order. Disable cache to fix, simply isn't a solution. With out cache my web server pushes 1.5 requests / second. With cache, I get around 32 requests / second. Displaying "click here to view your cart" isn't a solution. I need cache and I need my cart info.