Report this

What is the reason for this report?

App Platfrom - Laravel Application Caching

Posted on June 13, 2024

I have tried a few tutorials and ways to implement caching in my Laravel application by adding middlewares, editing .htaccess, modifing headers and so on. Sadly nothing seems to work and I can’t find a way to configure the server on the App Platform to cache my images and everything else with Cloudflare.

My Cache-Control header is Private in every image request

Accept-Ranges:
bytes

Alt-Svc:
h3=":443"; ma=86400

Cache-Control:
private

Cf-Cache-Status:
BYPASS

Cf-Ray:
892ef02f4aa33132-SOF

Content-Length:
17733

Content-Type:
image/png

Date:
Thu, 13 Jun 2024 03:19:17 GMT

Etag:
"4545-11ef9b484c240"

Last-Modified:
Tue, 01 Jan 1980 00:00:01 GMT

Nel:
{"success_fraction":0,"report_to":"cf-nel","max_age":604800}

Report-To:
{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=US0j8ShkRBdTvkxppLYfdlrr1ylryKteD9sF%2FQ%2FFXG7896C%2B%2FmoPZS5pyDtBeiH75E5ApVhVE9z7If9pp2Io9uC4V%2FScungiIG4Y%2BrRQjZivZ0Vm8dDb8WQkQnBcVGriTuHoJAqv328nUVF9oFY%3D"}],"group":"cf-nel","max_age":604800}

Server:
cloudflare

Vary:
Accept-Encoding

X-Do-App-Origin:
13fe4637-ea1a-4078-b991-409170ff0100

X-Do-Orig-Status:
200

For better understanding of the issue, you can visit https://thronetides.com/landing. I would really appreciate some help



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey!

After you’ve setup your Laravel middleware, have you also setup your Cloudflare settings?

As stated in this useful blog post here, you should be able to get this to work with the following setup:

  • Don’t configure any cache headers on the server side
  • Handled cache control headers within Laravel as you’ve done already
  • Changed setting to make sure Cloudflare respected my custom headers

On the Cloudflare side, as per the blog post, you would need to do the following:

  • Under Page Rules within Cloudflare, it’s important when you’re wanting to set custom cache levels that within Cloudflare you have “Origin Cache Control”, switched on.
  • Also under Caching > Configuration, also make sure you have “Browser Cache TTL” set to “Respect Existing Headers”.
  • If either of those are not set, Cloudflare will set its own cache level and will ignore anything you’ve set.

Let me know how this goes!

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.