Thank you eldhose.
After I set my website to Cache-Control: public, max-age=2628000, and add another rule Edge Cache TTL: 4 hours with Cache Level: Cache Everything, it works!
According to Customizing Cloudflare’s cache and the question from StackExchange:
Resources that match a Cache Everything Page Rule are still not cached if the origin web server sends a Cache-Control header of max-age=0 , private , no-cache , or an Expires header with an already expired date. Include the Edge Cache TTL setting within the Cache Everything Page Rule to additionally override the Cache-Control headers from the origin web server.
If the Cache-Control header is set to “private”, “no-store”, “no-cache”, or “max-age=0”, or if there is a cookie in the response, then CloudFlare will not cache the resource.
Laravel default response is Cache-Control: no-cache, private, no wonder the Cache Everything didn’t work.
According to Customizing Cloudflare’s cache and Understanding and Configuring Cloudflare Page Rules:
When combined with an Edge Cache TTL > 0 , Cache Everything removes cookies from the origin web server response.
So, I need to clean the cache on the server(actually I still don’t know what it is and why I need to do this). Anyway, after I add another rule Edge Cache TTL: 4 hours, it works.
Here are links of how to set to Cache-Control: public, max-age=2628000 in laravel:
- Use cache.headers in your route
- Make sure cache.headers is in your routeMiddleware