Understanding Shopify Cache

Highlighted
New Member
7 0 0

I can't find info anywhere about shopify's cache system.

 

I understand if the template is modified the cache gets cleared and the next call will build a new cache. But I'm curious about what other actions end up invalidating the cache?  

 

And more important, what happens if we update product info; images, stock quantity, etc? will this also empty the cache? Will certain apps cause the cache to rebuild periodically?

 

The reason for my question is that on our shop, houseandhold.com the TTFB (Time to first byte) is really high on collection pages if the shop is uncached (4-6 seconds). And a lot of time the shop is uncached without any manual modification on the template. Just trying to find the reason why the site is uncached so often.  It seems the site only stays cached for 5-10 minutes at a time.

0 Likes
Highlighted
Shopify Partner
29 1 11

Hi @DQuin 

 

Glad someone else is looking at this ;)

 

**Caveat: the following is based on some cursory testing - making changes and measuring TTFB, and what we have inferred from that.**

 

From what I can see, updating products causes the catalogue (PLP, PDP) pages to slow down (possibly as they're being de-cached), as evidenced by the following behaviour:

 

  1. Visit collection page for first time (TTFB c. 1 second - this is a basic template, those with extra logic will be longer)
  2. Visit collection page again soon after (TTFB c .3s) <- presumably because we're hitting the cache
  3. Update product via admin or API
  4. Visit collection page again (TTFB back to about 1 second)

(I'm using collection pages here as they seem to be more markedly affected than product pages). Furthermore, if you have inventory management switched on then you also see this slowdown after a sale is made. Our theory here is that this is because the inventory is updated on the products sold (and inventory update = product update):

 

  1. Visit collection page for first time (TTFB c. 1 second)
  2. Visit collection page again soon after (TTFB c .3s) <- presumably this is cached
  3. Place an order
  4. Visit collection page again (TTFB back to about 1 second)

Could product updates be the cause of your regular de-caching? Do you have any apps that might be modifying product data or stock levels on a regular basis? On top of this, there does sometimes seem to be a regular de-caching of pages at some pre-determined interval.

 

If the above is true, then this would mean that busier sites are less well cached than quieter ones. It's understandable why Shopify would require this behaviour - say if I had added a customisation to my template to show a 'low stock' message when the inventory goes below 5 units, I'd want that reflected right away - and this system allows that.

 

All this said, your pages taking 4s to generate - this does seem excessive and it might be that there's some inefficient liquid code in there somewhere. Have you seen this: https://developers.shopify.com/changelog/debug-your-liquid-render-performance-using-shopify-theme-in... ? It might help you determine if there are some liquid-related issues.

 

I'm interested to hear if you/anyone else can replicate/extend/debunk the theory as outlined above. Keen to get TTFBs down as low as possible, so any ideas as to how to make the site as 'cached' as possible would be warmly received.

0 Likes