ostark / upper

Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
MIT License
102 stars 22 forks source link

Cloudflare api file list limit #23

Closed petetak closed 5 years ago

petetak commented 5 years ago

Cloudflare has a 500 url limit for cache invalidation so it would make sense to split the array into smaller chunks and call the api with these chunks.

https://github.com/ostark/upper/blob/b8a584a41d4a85f739770b144d380729fe7f7dd1/src/drivers/Cloudflare.php#L61

I'm happy to work on this and submit a PR but I don't want to change the interface to purgeUrls - ie: I'm not sure what it should return if I made this change.

If you let me know what you would like to do I'll work on it.

petetak commented 5 years ago

In fact maybe the return value is not important as we are interested only in exceptions from the call to Cloudflare:

https://github.com/ostark/upper/blob/82c23f8c2a872d442e16cf979538303cccdf6405/src/drivers/AbstractPurger.php#L37

So perhaps a decent solution is to chunk the file list and make multiple calls to the Cloudflare api and then return true at the end of it?

petetak commented 5 years ago

For example: https://github.com/supercool/upper/blob/7ef2a4e4a3ad45429d9ac7930219a956d475b598/src/drivers/Cloudflare.php#L62

ostark commented 5 years ago

Thanks @petetak - it will take a bit to review your suggestion. Please be patient.

petetak commented 5 years ago

No problem at all. FYI I've put this into production on a site and it's now not getting stuck on cache clear tasks (which it was before) and the upper-cache table is not as huge as it was.

I'll let you know if I run into any issues.

ostark commented 5 years ago

The API docs are ambiguous:

Zone error codes

1094 | Exceeded maximum amount of 500 files that can be purged on a single request

Purge Files by URL

(array) files max length: 30

And in the Cloudflare Control Panel under Caching > Custom Purge, they tell me the limit is 30.

You will need to specify the full path to the file. Wildcards are not supported with single URL purge at this time. You can purge up to 30 URLs at a time.

--

@petetak I'll go with 30, okay? This should not hurt even if the limit is 500.

petetak commented 5 years ago

That sounds great!