PHP code example of adriansuter / twig-cache-busting
1. Go to this page and download the library: Download adriansuter/twig-cache-busting 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/ */
adriansuter / twig-cache-busting example snippets
use AdrianSuter\TwigCacheBusting\CacheBusters\QueryParamCacheBuster;
use AdrianSuter\TwigCacheBusting\CacheBustingTwigExtension;
//...
$twig->addExtension(
CacheBustingTwigExtension::create(
new QueryParamCacheBuster('/home/htdocs/public')
)
);
use AdrianSuter\TwigCacheBusting\HashGenerators\FileMD5HashGenerator;
new QueryParamCacheBuster('/home/htdocs/public', new FileMD5HashGenerator())
use AdrianSuter\TwigCacheBusting\CacheBusters\FileNameCacheBuster;
use AdrianSuter\TwigCacheBusting\CacheBustingTwigExtension;
// ...
$twig->addExtension(
CacheBustingTwigExtension::create(
new FileNameCacheBuster('/home/htdocs/public')
)
);
use AdrianSuter\TwigCacheBusting\HashGenerators\FileMD5HashGenerator;
new FileNameCacheBuster('/home/htdocs/public', new FileMD5HashGenerator())
use AdrianSuter\TwigCacheBusting\CacheBusters\DictionaryCacheBuster;
use AdrianSuter\TwigCacheBusting\CacheBustingTwigExtension;
use AdrianSuter\TwigCacheBusting\Dictionaries\ArrayDictionary;
// ...
$twig->addExtension(
CacheBustingTwigExtension::create(
new DictionaryCacheBuster(
new ArrayDictionary([
'assets/image.jpg' => 'assets/cb-1c2d7c4s36d47d.jpg',
])
)
)
);
$twig->addExtension(
CacheBustingTwigExtension::create(
new QueryParamCacheBuster('/home/htdocs/public'),
'base-path'
)
);
$twig->addExtension(
CacheBustingTwigExtension::create(
new QueryParamCacheBuster('/home/htdocs/public'),
null,
'cb'
)
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.