{"id":19689143,"url":"https://github.com/yediyuz/laravel-cloudflare-cache","last_synced_at":"2025-04-04T18:05:09.200Z","repository":{"id":213607357,"uuid":"734458925","full_name":"yediyuz/laravel-cloudflare-cache","owner":"yediyuz","description":"Serve millions of requests by caching with Cloudflare","archived":false,"fork":false,"pushed_at":"2024-07-10T09:06:23.000Z","size":63,"stargazers_count":253,"open_issues_count":4,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T17:05:21.909Z","etag":null,"topics":["cache","cloudflare","cloudflare-cache","laravel","yediyuz"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yediyuz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-21T18:26:08.000Z","updated_at":"2025-03-18T23:03:20.000Z","dependencies_parsed_at":"2024-03-14T11:32:10.175Z","dependency_job_id":"f4d7e6bf-3917-4507-a240-53f5312d734f","html_url":"https://github.com/yediyuz/laravel-cloudflare-cache","commit_stats":null,"previous_names":["yediyuz/laravel-cloudflare-cache"],"tags_count":3,"template":false,"template_full_name":"yediyuz/laravel-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yediyuz%2Flaravel-cloudflare-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yediyuz%2Flaravel-cloudflare-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yediyuz%2Flaravel-cloudflare-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yediyuz%2Flaravel-cloudflare-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yediyuz","download_url":"https://codeload.github.com/yediyuz/laravel-cloudflare-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226213,"owners_count":20904465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cloudflare","cloudflare-cache","laravel","yediyuz"],"created_at":"2024-11-11T18:42:54.620Z","updated_at":"2025-04-04T18:05:09.180Z","avatar_url":"https://github.com/yediyuz.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://banners.beyondco.de/Laravel%20Cloudflare%20Cache.png?theme=dark\u0026packageManager=composer+require\u0026packageName=yediyuz%2Flaravel-cloudflare-cache\u0026pattern=architect\u0026style=style_1\u0026description=Serve+millions+of+requests+by+caching+with+Cloudflare\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=server\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://banners.beyondco.de/Laravel%20Cloudflare%20Cache.png?theme=light\u0026packageManager=composer+require\u0026packageName=yediyuz%2Flaravel-cloudflare-cache\u0026pattern=architect\u0026style=style_1\u0026description=Serve+millions+of+requests+by+caching+with+Cloudflare\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=server\"\u003e\n  \u003cimg alt=\"Package Image\" src=\"https://banners.beyondco.de/Laravel%20Cloudflare%20Cache.png?theme=light\u0026packageManager=composer+require\u0026packageName=yediyuz%2Flaravel-cloudflare-cache\u0026pattern=architect\u0026style=style_1\u0026description=Serve+millions+of+requests+by+caching+with+Cloudflare\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=server\"\u003e\n\u003c/picture\u003e\n\n# Laravel Cloudflare Cache\n\n\u003cp\u003e\n    \u003ca href=\"https://github.com/yediyuz/laravel-cloudflare-cache/actions\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/yediyuz/laravel-cloudflare-cache/tests.yml?branch=master\u0026label=tests\" alt=\"Test Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/yediyuz/laravel-cloudflare-cache\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/yediyuz/laravel-cloudflare-cache.svg?style=flat-square\" alt=\"Latest Release\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/mertasan/tailwindcss-variables/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-green.svg?label=license\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nYou can serve millions of requests with this package. This package provides cacheable routes for Cloudflare. Thanks to Cloudflare, your static pages are served efficiently, reducing the load on your servers if they are cached for the TTL (Time to Live) duration. You can purge the cache whenever you need with this package.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require yediyuz/laravel-cloudflare-cache\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"cloudflare-cache-config\"\n```\n\nAdd environment variables to .env file\n\n```dotenv\nCLOUDFLARE_CACHE_EMAIL=info@example.com #Cloudflare account email address\nCLOUDFLARE_CACHE_KEY=XXXXXXX #Cloudflare API_KEY\nCLOUDFLARE_CACHE_IDENTIFIER=XXXXXXX #ZONE_ID\nCLOUDFLARE_DEFAULT_CACHE_TTL=600 #10 minutes\nCLOUDFLARE_CACHE_DEBUG=false\n```\n\n### Add `Rule` on Cloudflare\nTo active caching on static pages, you need to add `page rule` **OR** `cache rule` on Cloudflare.\n\nFor page rule:\n- If the URL matches: `www.example.com/*`\n- Setting: Cache Level\n- Value: Cache Everything\n\nFor the cache rule:\n- Field: hostname\n- Operator: equals\n- Value: `example.com`\n- Then: Eligible for cache\n\nhttps://developers.cloudflare.com/cache/how-to/cache-rules/create-dashboard/\n\n## Usage\n\n### Define routes to cache\nYou can use cache groups for your static contents.\n```php\nRoute::cache()-\u003egroup(function () {\n    Route::get('/content', function () {\n        return 'content';\n    });\n});\n```\n\nYou can use cache tags, so you can clear your caches easily. Specify custom ttl for expire time in seconds. When you do not pass ttl, it will use default ttl given in the config.\n```php\nRoute::cache(tags: ['tag1', 'tag2'], ttl: 600)-\u003egroup(function () {\n    Route::get('/content_with_tags', function () {\n        return 'content';\n    });\n});\n\nRoute::cache(tags: ['staticPages'])-\u003egroup(function () {\n    //\n});\n```\n\n\u003e [!WARNING]  \n\u003e Be careful caching your routes! Do not cache your dynamic pages such as admin panel or form based pages!\n\n### Clear Cache\n\n#### Purges everything\nhttps://developers.cloudflare.com/cache/how-to/purge-cache/purge-everything/\n```php\nCloudflareCache::purgeEverything()\n```\n\n#### Purges by urls\nhttps://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/\n```php\nCloudflareCache::purgeByUrls([\n    'https://example.com/hello',\n])\n```\n\n#### Purges by prefixes (Enterprise only)\nhttps://developers.cloudflare.com/cache/how-to/purge-cache/purge_by_prefix/\n```php\nCloudflareCache::purgeByPrefixes([\n    'www.example.com/foo',\n])\n```\n\n#### Purges by tags (Enterprise only)\nhttps://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/\n```php\nCloudflareCache::purgeByTags([\n    'staticPages',\n])\n```\n\n#### Purges by hostname (Enterprise only)\nhttps://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-hostname/\n```php\nCloudflareCache::purgeByHosts([\n    'www.example.com',\n    'images.example.com',\n])\n```\n\nPost update example to clear cache\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Http\\Requests\\UpdatePostRequest;\nuse App\\Models\\Post;\nuse Yediyuz\\CloudflareCache\\Facades\\CloudflareCache;\n\nclass PostController extends Controller\n{\n    public function update(Post $post, UpdatePostRequest $request)\n    {\n        $post-\u003eupdate($request-\u003evalidated());\n\n        CloudflareCache::purgeByUrls([\n            route('post.show', $post-\u003eid)\n        ]);\n\n        return back()-\u003ewith('message', 'Post updated and url cache purged');\n    }\n}\n```\n\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/yediyuz/.github/blob/master/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail security@yediyuz.com instead of using the issue tracker.\n\n## Credits\n- [Emre Dipi](https://github.com/emredipi)\n- [Mert Aşan](https://github.com/mertasan)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyediyuz%2Flaravel-cloudflare-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyediyuz%2Flaravel-cloudflare-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyediyuz%2Flaravel-cloudflare-cache/lists"}