• Reading time ~ 1 min
  • 25.03.2024

The Cloudflare Cache package for Laravel provides cacheable routes, allowing you to serve millions of requests for static pages efficiently. You can define a group of cacheable routes with the Laravel router, including tags. This package makes it easy to start caching with Cloudflare using the Route::cache() method:

Route::cache(tags: ['tag1', 'tag2'], ttl: 600)->group(function () {
    Route::get('/content_with_tags', function () {
        return 'content';
Route::cache(tags: ['staticPages'])->group(function () {

This package gives you APIs to purge all content, specific URLs, prefixes/tagged URLs (enterprise), and more. As an example, let's say you want to cache articles (Posts) with Cloudflare and purge the cache whenever the article is updated:

namespace App\Http\Controllers;

use App\Http\Requests\UpdatePostRequest;
use App\Models\Post;
use Yediyuz\CloudflareCache\Facades\CloudflareCache;

class PostController extends Controller
    public function update(Post $post, UpdatePostRequest $request)

            route('post.show', $post->id)
        return back()->with('message', 'Post updated and url cache purged');

You can learn more about this package, get full installation instructions, and view the source code on GitHub.


No comments yet
Yurij Finiv

Yurij Finiv

Full stack


Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
Ukraine, Lutsk