1

So we have a Commerce project that shows lots of products per page/category as per any standard store.

Each product block comprises:

  • Product name
  • Product price
  • Brand (via category field) [eager loaded]
  • Image [eager loaded]

Is it worth caching each of these blocks with a unique key?

3

In short, it's worth caching anything that is at all time expensive, really.

It's always going to be significantly quicker to retrieve a cached chunk from the DB by key versus parsing a template section - and especially so a complex one with many related elements being pulled in.

However, if those are live products, i.e. with add to cart forms, you'll need to make sure the forms remain valid (think about current CSRF token, etc - you can insert these with JS on page load, for example) - and that your cache breaks whenever the cached thing is updated (which should mostly be automatic).

Note that once you start caching a lot of different things, it can take several seconds for all the stale cache chunks on complex pages to be deleted after you make changes in the control panel (you can see the little queue thing executing this after you save your updates) - so it will mean that your content changes will no longer be literally instant, and this can confuse if you're not aware of it happening. In our case it can take up to a minute before it all washes through, so your content editors need to be aware of this.

| improve this answer | |
  • Thanks Jeremy, super helpful. – James Greig Sep 26 '19 at 7:53

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.