PHP code example of glueful / cdn

1. Go to this page and download the library: Download glueful/cdn 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/ */

    

glueful / cdn example snippets


return [
    // Master switch for edge caching.
    'enabled' => env('EDGE_CACHE_ENABLED', false),

    // CDN provider name. EMPTY by default — no vendor bias is shipped.
    // Must match a key in the `adapters` map below to resolve an adapter.
    'provider' => env('EDGE_CACHE_PROVIDER', ''),

    // Default TTL (seconds) for edge-cached responses.
    'default_ttl' => env('EDGE_CACHE_TTL', 3600),

    // Route-specific cache rules.
    'rules' => [
        // 'home' => ['ttl' => 600, 'vary_by' => ['Accept-Encoding']],
    ],

    // Provider name -> adapter class map (see "Registering an adapter").
    'adapters' => [],
];

// config/cdn.php
'provider' => 'cloudflare',
'adapters' => [
    'cloudflare' => \Glueful\Extensions\Cdn\Adapters\CloudflareAdapter::class,
],

public function register(ApplicationContext $context): void
{
    $this->mergeConfig('cdn', [
        'adapters' => [
            'acme' => \Acme\Cdn\AcmeAdapter::class,
        ],
    ]);
}

use Glueful\Cache\Contracts\EdgeCacheInterface;

$edge = container($context)->get(EdgeCacheInterface::class);

if ($edge->isEnabled()) {
    $edge->purgeUrl('https://example.com/page');
    $edge->purgeByTag('products');
    $edge->purgeAll();
}
bash
# Enable (adds the provider FQCN to config/extensions.php + recompiles the cache)
php glueful extensions:enable cdn

# Disable (removes it)
php glueful extensions:disable cdn
bash
composer extensions:enable cdn
bash
php glueful extensions:list
php glueful extensions:info cdn
php glueful extensions:diagnose
bash
php glueful cache:purge --all
php glueful cache:purge --url=https://example.com/page
php glueful cache:purge --tag=products