API / Automated method to clear product page cache

API / Automated method to clear product page cache

Chris_Push
Shopify Partner
5 0 4

If a product page is viewed / refreshed fairly heavily, it moves into a Shopify storefront cache layer.

Once in the cache, it doesn't refresh data - for example, the liquid variable for the current store time.

We are using this liquid time variable to understand if a product should be made available for pre-order on the store.

 

The only reliable method we've identified to clear storefront cache for a product page is to use the Shopify Admin and manually make a change to the product there.

 

We've tried using an automated API update of product data to see if making a change will force a refresh of the cache - but via the API, it doesn't appear it clears the cache.

 

Does anyone have any experience of cache busting a partucular page via the API or have any clever workarounds?

 

 

 

Does anyone know of any approaches that will reliably clear the Shopify storefront cache for a product page?

Replies 8 (8)

JoesIdeas
Shopify Partner
2490 229 672

An alternative idea for now, what if you created a JavaScript function that executes on pageload and checks the time you have showing, verifies it, and updates it if it's different?

 

You could also use setInterval() to check every minute in case they have the page open and time passes... though if it's just a date in the future that may not apply here.

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics
Chris_Push
Shopify Partner
5 0 4

Hi @JoesIdeas I dislike the client polling concept in general because it doesn't scale and so if there is a high traffic event - there's a server that will be receiving a hammering 🙂 Some sort of backend ajax check may be th only way through here though - but again, it's really not the approach I want to take.

But it doesn't look like we have a way to bust the API in a controlled way. I was hoping the group mind of Community forums might come up with a way to do this - but I fear from the responses so far, it's not possible.

JoesIdeas
Shopify Partner
2490 229 672

I hear ya on the polling, that might just be an assumption you have about not scaling based on other experiences (like having a single server without much bandwidth, rather than a CDN and distributed server load), I haven't witnessed a scale problem and I've seen 3rd party apps polling... but ya not a root fix just an idea for a temporary workaround.

 

Tough one to solve the best way without Shopify's help on controlling that cache, good luck I hope you find a good solution.

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics

Kalen_Jordan
Shopify Partner
803 39 147

Interesting - I'm also curious about this. From a quick search it doesn't seem to be possible to clear the cache automatically.

 

Chris_Push
Shopify Partner
5 0 4

I will continue to search - a controlled API method to bust a cache on a product page would be extremely useful in my use case, and I'm sure in others.
An admin product save does indeed bust the cache in this way - so there must be a process that carries this out - but it's not exposed to the API.

Kalen_Jordan
Shopify Partner
803 39 147

How exactly are you using the store time liquid variable to determine whether the product should be available for pre-order or not? I wonder if there is another solution to this problem.

Chris_Push
Shopify Partner
5 0 4

Esentially on page 'load' we use the Liquid variable for current time. (I apologise for not having the exact variable used to hand.) We then use this to determin the output of whether the button is active as a pre-order or inactive.

I want this logic to be based on server time - not local user time to prevent easy spoofing.

onescales
Shopify Partner
117 3 18

Another way to think about it. In your links to your pages, from navigation, internal etc, you can add a ?id=random-number so that cache is forced to refreshed every new id

OneScales.com Teaches Shopify and Solves Ecommerce Problems for Free. See our Youtube Channel for Tutorials - https://www.youtube.com/@onescales
We Also Share Insight about E-commerce, Web, Tech, AI, Analytics, SEO, PPC, Marketing and More.