PHP code example of joostvanveen / laravel-litespeedcache
1. Go to this page and download the library: Download joostvanveen/laravel-litespeedcache 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/ */
joostvanveen / laravel-litespeedcache example snippets
// Cache is enabled
config(['litespeedcache.defaults.enabled' => true]);
// ESI is enabled
config(['litespeedcache.defaults.esiEnabled' => true]);
// Whether or not to cache ajax calls
config(['litespeedcache.defaults.enable_ajax_cache' => false]);
// Array of request methods that should be cached
config(['litespeedcache.defaults.cache_http_verbs' => ['GET', 'HEAD']]);
// Whether or not to use the deafult middleware that comes with this package
config(['litespeedcache.defaults.use_middleware' => true]);
// Default cache type
config(['litespeedcache.defaults.type' => 'public']);
// Default TTL for cache in minutes
config(['litespeedcache.defaults.lifetime' => 240]);
// Array of URIs that should not be cached, can contain wildcards like '/admin*'
config(['litespeedcache.defaults.excludedUris' => [$csrfTokenUri . '*', $csrfFieldUri . '*']]);
// Array of query strings that should not be cached, can contain wildcards like '*utm_source=*'
config(['litespeedcache.defaults.excludedQueryStrings' => []]);
// Array of routes for this package
config(['litespeedcache.routes' => ['token' => $csrfTokenUri, 'field' => $csrfFieldUri] ]);
use LitespeedCache;
[...]
// Cache use all default settings from config.
LitespeedCache::cache();
// Purge the cache
LitespeedCache::purge();
// Full options example
// You can also set $excludedUris and $excludedQueryStrings in config.
$excludedUris = [
'checkout*',
'admin*',
];
$excludedQueryStrings = [
'*direction=*',
];
LitespeedCache::setType('private')->setLifetime(120)
->addTags(['articles', 'en_GB'])
->addVary('value=mysubdomain')
->setExcludedUrls($excludedUris)
->setExcludedQueryStrings($excludedQueryStrings)
->cache();
// Purge cache using tags.
LitespeedCache::addTags('articles')->purge();
// If the lifetime is set to 0 the page will not be cached
(new Cache)->setEnabled(true)->setLifetime(0)->cache();