Some API responses are being cached

Hey guys, Our woocommerce store is using checkout-x and we have issues with discount coupons due to API caching.How do I reconfigure that ?

Here is the response from their support team.

So, what you need to do is to reconfigure Cloudflare . Currently, some API responses are being cached, and caching API requests is not a good practice in general because of the risk for stale responses.

Thanks
Chris

Request like this one are not currently cached https://mydomain.com/wp-json/wc/v3/coupons?consumer_key=consumer_secret=**
While requests to the same URL with other parameters are currently cached https://mydomain.com/wp-json/wc/v3/coupons?code=whatever&consumer_key=***&consumer_secret=

API Caching? Cloudflare doesn’t cache dynamic requests. Do you have any Caching Page Rules or Automatic Platform Optimization enabled?

Hi there, and thank you for your reply. I do not have any rules in place and I am not sure about Automatic Platform Optimization

Hey guys, Our woocommerce store is using checkout-x and we have issues with discount coupons due to API caching.How do I reconfigure that ?

Here is the response from their support team.

So, what you need to do is to reconfigure Cloudflare . Currently, some API responses are being cached, and caching API requests is not a good practice in general because of the risk for stale responses.

It turned up that we synced the coupons when they were created/updated as expected, but they were deleted afterward for no reason. This happened because:

  • We sync the discounts every time they are used at the checkout. We update them if they are stale and delete them if they are not found in WooCommerce.
  • We use a more specific request when getting the data from WC vs when we sync - adding the code=CODE parameter in the URL. Turns out your store is using Cloudflare and Cloudflare returns us a cached version of this URL’s response (errored response - “invalid_grant”), the parsing of the response errors out, we rescue the error and return nil which leads to deleting the discount.

So, what you need to do is to reconfigure Cloudflare . Currently, some API responses are being cached, and caching API requests is not a good practice in general because of the risk for stale responses. Cloudflare has a guide on how to use them for APIs. Please, follow the recommendations in it https://support.cloudflare.com/hc/en-us/articles/200504045-Using-Cloudflare-with-your-API.

For a quick temporary fix, you can at least purge the Cloudflare cache. Here are some specific technical info about the caching problem:

  • Request like this one are not currently cached https://mydomain.com/wp-json/wc/v3/coupons?consumer_key=*******consumer_secret=*********
  • While requests to the same URL with other parameters are currently cached https://mydomain.com/wp-json/wc/v3/coupons?code=whatever&consumer_key=*******&consumer_secret=****

Thanks
Chris

As I said, Cloudflare doesn’t cache dynamic content by default. If you need more specific guidance, please post the domain name.

“checkout” is not proxied by Cloudflare.

The main domain has server caching:

x-cache-enabled: True

Cloudflare is not caching dynamic content for that domain.

thanks,

here are the URLs they mentioned. Not sure what rules should we configure as per their comments. Thanks in advance.

Here are some specific technical info about the caching problem:

  • Request like this one are not currently cached https://twofussyblokes.com/wp-json/wc/v3/coupons?consumer_key=*******consumer_secret=*********
  • While requests to the same URL with other parameters are currently cached https://twofussyblokes.com/wp-json/wc/v3/coupons?code=whatever&consumer_key=*******&consumer_secret=****

so i do not need to crerate any page rules as suggested?

Thanks

Not here. That won’t do any good based on the evidence I’ve seen.

You’ll have to ask the host if there’s a way to disable that server cache.

do you mean disable CloudFlare cache for the domain ? Thanks

Cloudflare is not your host.