0

I use the following cache system, specified in the header of all pages:

{% set expiry = now|date_modify('+1 day') %}
{% header "Cache-Control: max-age=" ~ expiry.timestamp %}
{% header "Pragma: cache" %}
{% header "Expires: " ~ expiry|date('D, d M Y H:i:s', 'GMT') ~ " GMT" %}

This does not coexist properly with the variable {{ cart.lineItems|length }} which displays on each page the number of products currently in the cart.

When I update the basket and go back to a previously visited pages, the cart is not up to updated and retains the value displayed during the previous visit.

To be more specify: I do not use the {% cache %} tags on the template part which displays the shopping cart.

0

I do not think you can achieve this with browser caching - there's no concept of cache 'escaping' with this type of caching. Indeed, there's currently no concept of cache escaping with Craft's {% cache %} tag either...which is a shame.

In general, even, caching at the page level when using Commerce carts is tough/impossible - e.g. you'll also need fresh CSRF tokens for cart operations etc.

Currently (without plugins anyway) - the best thing is probably to use Craft cache tags for static page elements and simply avoid caching things like your cart count and add to cart forms etc. And put your site on a nice fast server :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.