#Laravel + Cloudflare cache API

28 messages · Page 1 of 1 (latest)

tropic goblet
#

I have built a nice little media-service with Laraval, thats behind a Cloudflare cache. Its caching js files and img files, that together forms a gallery that can be embedded on other pages.

I have a bit of a problem with undertanding Cloudflares cache. I hope someone here has an idea of how to work with it.

When images and js-files are updated, i need to reflush the cache on Cloudflare. Im doing this with the Cloudflare API.

However, the jsfiles and images arent updated, even in incognito (etc).

I tried setting the Browser TTL to 2 minuttes, however this didnt solve it.

Im wondering now, if the Edge TTL needs to go down - if the ordering of Cloudflare Cache to reflush only reaches Cloudflares "local" cache and not the Edge Cache - and if the Edge Cache TTL really hits Cloudflares "local" cache - or if Edge Cache downloads from the original source of the files ?

Does anyone have any experience with this - and if theres any great Laravel + Cloudflare resources that explains this?

Thanks in advance !

naive prawn
#

If you're using Vite to build your assets they would all have a hash in the filename, so there wouldn't be a need to clear the cache. Even with Mix that's the case, as that appends a ?version= to the URL, so it's a new URL when you build new assets

tropic goblet
naive prawn
#

Can't you then apply some sort of versioning there? So you'd use URLs that have a version number attached or some sort of hash. That way you'd just provide a new URL

tropic goblet
# naive prawn Can't you then apply some sort of versioning there? So you'd use URLs that have ...

Sadly no, though its a good idea. The websites implement these galleries as including the .js file (without versioning) and booting it up - and only thing i would be able to do is to bypass the cache alltogether for the .js files - but then theres no cache.

The clients implementing the scripts "arent supposed" to change anything once theres an update.

The only workaround i have found at the moment would be to have the latest version saved in a Cloudflare keystore/D1 base - then have a worker intercepting all the .js calls and simply just appending the ?version in a fetch to the local cloudflare cache.

Though - its not my prefered method - i would like to keep it simple with "just" an API call from Laravel to Cloudflare 🙂

marble girder
#

I'm pretty sure you can clear the cache from cloudflare from a specific url

#

With an api

#

You can see in the cloudflare response if it was a HIT or not in the headers

#

If HIT then it was cached before, otherwise it was fetched from the remote server

tropic goblet
marble girder
#

What does the header tell you?

tropic goblet
# marble girder What does the header tell you?

its giving me an thumbs up on the results - but i dont see it reflected on the edge result.

Thats why i was wondering if there was more cache options for Edge TTL that could/should be enbled

marble girder
#

There should be a X-Cache-status

tropic goblet
#

yes - the problem is that I do not see the latest version reflected from the result on the web even though it sends me a HIT.

marble girder
#

Could you provide me with an example?

#

Yes, HIT would mean it was cached

#

So you're not clearing it properly then

tropic goblet
#

@marble girder it is correctly understood that the cache purge SHOULD work instantly accross the edge ?

#

if yes - then I must be the one making an error

marble girder
#

Could be a couple of minutes, but no longer than 2

#

Pretty sure

tropic goblet
#

okay, then i must be doing something else wrong then

marble girder
#

Ive seen it purge instantly omst of the time

#

You're not purging the cache properly it seems like

tropic goblet
marble girder
#

I really don't know. I'm sorry

tropic goblet
#

Thank you both for your input !