PHP code example of eminos / statamic-cloudflare-cache

1. Go to this page and download the library: Download eminos/statamic-cloudflare-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eminos / statamic-cloudflare-cache example snippets


'zones' => [
    // Map domains to zone IDs
    'example.com' => 'zone_id_123',
    'example.fr' => 'zone_id_456',
],

return [
    // Enable or disable the addon
    'enabled' => env('CLOUDFLARE_CACHE_ENABLED', true),
    
    // Cloudflare API credentials
    'api_token' => env('CLOUDFLARE_API_TOKEN', ''),
    
    // Single zone configuration (backward compatibility)
    'zone_id' => env('CLOUDFLARE_ZONE_ID', ''),
    
    // Multi-zone configuration for multisite setups
    'zones' => [
        // 'domain.com' => 'zone_id_here',
        // 'another-domain.com' => 'another_zone_id',
    ],
    
    // Configure which events trigger cache purging
    'purge_on' => [
        'entry_saved' => true,
        'entry_deleted' => true,
        'term_saved' => true,
        'term_deleted' => true,
        'asset_saved' => true,
        'asset_deleted' => true,
        'collection_tree_saved' => true,
        'nav_tree_saved' => true,
        'global_set_saved' => true,
        'global_set_deleted' => true,
        'url_invalidated' => true, // Statamic Static Cache: UrlInvalidated event
        'static_cache_cleared' => true, // Statamic Static Cache: StaticCacheCleared event
    ],

    // When enabled, only Statamic Static Cache events are handled (UrlInvalidated/StaticCacheCleared).
    // Legacy addon content events are skipped in this mode.
    'use_statamic_static_cache_invalidation' => env('CLOUDFLARE_CACHE_USE_STATAMIC_STATIC_CACHE_INVALIDATION', false),

    // Dispatch purge jobs to the queue instead of running synchronously
    'queue_purge' => env('CLOUDFLARE_CACHE_QUEUE_PURGE', false),
    
    // Advanced settings
    'purge_urls' => true, // Purge specific URLs if possible
    'purge_everything_fallback' => true, // Fallback to purging everything if specific URLs can't be determined
    'debug' => env('CLOUDFLARE_CACHE_DEBUG', false), // Log API call attempts when purging
];
bash
php artisan vendor:publish --tag="cloudflare-cache-config"