Download the PHP package fuelviews/laravel-cloudflare-cache without Composer
On this page you can find all versions of the php package fuelviews/laravel-cloudflare-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fuelviews/laravel-cloudflare-cache
More information about fuelviews/laravel-cloudflare-cache
Files in fuelviews/laravel-cloudflare-cache
Package laravel-cloudflare-cache
Short Description Laravel cloudflare cache package
License MIT
Homepage https://github.com/fuelviews/laravel-cloudflare-cache
Informations about the package laravel-cloudflare-cache
Laravel Cloudflare Cache
A powerful and intuitive Laravel package for managing Cloudflare cache purging directly from your Laravel application. Streamline your cache management workflow with comprehensive commands, validation, and seamless integration.
๐ Requirements
- PHP 8.3+
- Laravel 10.x, 11.x, or 12.x
- Cloudflare account with API access
๐ Installation
Install the package via Composer:
Quick Setup
Run the install command for guided setup:
This will:
- Publish the configuration file
- Guide you through credential setup
- Validate your configuration
- Provide helpful next steps
Manual Setup
Alternatively, you can manually publish the configuration:
โ๏ธ Configuration
Environment Variables
Add your Cloudflare credentials to your .env
file:
Getting Your Cloudflare Credentials
-
API Key: Create an API token at Cloudflare API Tokens
- Use the "Custom token" option
- Required permissions:
Zone:Zone:Read
,Zone:Cache Purge:Edit
- Zone Resources: Include specific zones or all zones
- Zone ID: Find your Zone ID in your Cloudflare dashboard
- Go to your domain overview
- Find "Zone ID" in the right sidebar
- It's a 32-character hexadecimal string
Configuration File
The published configuration file config/cloudflare-cache.php
:
๐ฏ Basic Usage
Using the Facade
Using Dependency Injection
Environment-Aware Functionality
The package includes smart environment detection:
The ive()
method returns true
when:
- Running unit tests
- Debug mode is enabled (
CLOUDFLARE_CACHE_DEBUG=true
) - Application is in production environment and credentials are configured
๐ ๏ธ Artisan Commands
Cache Clear Command
Purge all Cloudflare cache:
Success Output:
Error Output:
Validate Configuration
Check your configuration for issues:
Successful validation:
With errors:
Check Status
Test your API connection and configuration:
Successful status check:
With configuration issues:
๐๏ธ Advanced Usage
Integration with Events
Clear cache automatically when content changes:
Using in Queue Jobs
For better performance, queue cache purging operations:
Custom Service Provider
Publish and customize the service provider:
This publishes CloudflareCacheServiceProvider
to your app/Providers
directory for customization.
Middleware Integration
Create middleware to automatically purge cache:
๐ก๏ธ Exception Handling
The package provides comprehensive error handling:
๐งช Testing
Running Package Tests
Testing in Your Application
The package automatically handles testing environments:
Feature Testing
๐ Troubleshooting
Common Issues
โ "API Key not configured"
- Ensure
CLOUDFLARE_CACHE_API_KEY
is set in your.env
file - Run
php artisan config:clear
after updating environment variables - Verify the API key has proper permissions
โ "Zone ID format appears invalid"
- Zone IDs should be exactly 32 characters (hexadecimal)
- Check your Cloudflare dashboard for the correct Zone ID
- Ensure no extra spaces or characters
โ "Request error: Invalid API Token"
- Verify your API token has the required permissions:
Zone:Zone:Read
Zone:Cache Purge:Edit
- Check that the token hasn't expired
- Ensure the token is active in your Cloudflare dashboard
โ "Request error: Zone not found"
- Verify the Zone ID matches your domain
- Ensure the API token has access to the specified zone
- Check that the zone is active in Cloudflare
Debug Mode
Enable debug mode for detailed information:
With debug mode enabled:
- Cache purging works in all environments
- Additional logging information is available
- The
ive()
method always returnstrue
Validation Commands
Use built-in validation to diagnose issues:
Logging
Check Laravel logs for detailed error information:
๐ API Reference
CloudflareCacheInterface
purgeEverything(): bool|string
Purges all cache from Cloudflare for the configured zone.
Returns:
string
: Operation ID on successfalse
: On failure (when API returns success: false)
Throws:
CloudflareCacheRequestException
: When API request fails
ive(): bool
Determines if cache purging should be performed based on environment and configuration.
Returns:
true
: When cache purging should be performedfalse
: When cache purging should be skipped
Available Commands
Command | Description |
---|---|
cloudflare-cache:install |
Guided installation process |
cloudflare-cache:clear |
Purge all Cloudflare cache |
cloudflare-cache:validate |
Validate configuration settings |
cloudflare-cache:status |
Check API connection and configuration |
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Development Setup
๐ Changelog
Please see CHANGELOG for more information on what has changed recently.
๐ Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
๐จโ๐ป Credits
- Joshua Mitchener
- Sweatybreeze
- Fuelviews
- Yediyuz
- Mertasan
- All Contributors
๐ License
The MIT License (MIT). Please see License File for more information.
Built with โค๏ธ by the Fuelviews team
All versions of laravel-cloudflare-cache with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.92
guzzlehttp/guzzle Version *