Answers.Body: <p>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 <code>{% cache %}</code> tag either...which is a shame.</p>
  
  <p>In <em>general</em>, 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.</p>
  
  <p>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 :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-17T00:13:19.273Z
Answers.LastActivityDate: 2016-12-17T00:13:19.273Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I use the following cache system, specified in the header of all pages:</p>
  
  <pre><code>{% 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" %}
  </code></pre>
  
  <p>This does not coexist properly with the variable <code>{{ cart.lineItems|length }}</code> which displays on each page the number of products currently in the cart.</p>
  
  <p>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.</p>
  
  <p>To be more specify: I do not use the <code>{% cache %}</code> tags on the template part which displays the shopping cart.</p>
  
Tags: <plugin-craftcommerce><cache><variable>
Title: How to update cart.lineItems while specifying HTTP cache headers?
ThreadText: # How to update cart.lineItems while specifying HTTP cache headers?
  
  (Asked by: username_0 on 2016-12-16)
  
  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.
  
  **Tags:** plugin-craftcommerce, cache, variable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-17. Score: 0 | Accepted answer
  
  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 :)
  
  
  ---
  
  