PHP code example of joostvanveen / litespeedcache

1. Go to this page and download the library: Download joostvanveen/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 / litespeedcache example snippets


use Joostvanveen\Litespeedcache\Cache;

[...]

// Cache the current URL as public with a cache lifetime of 120 minutes
$cache = new Cache;
$cache->cache(); // use default type and lifetime

// You can also use new Cache directly, like so:
(new Cache)->cache(); // use default type and lifetime
(new Cache)->cache('private', 360); // use explicit type and lifetime

// You can also use the setType() and setLifetime() methods
(new Cache)->setEnabled(true)->setType('private')->setLifetime(3600)->cache();

// If the lifetime is set to 0 the page will not be cached
(new Cache)->setEnabled(true)->setLifetime(0)->cache();

// Warm the cache for these URIs
$uris = [
    '/',
    '/about-us',
    '/contact',
];

$cache = (new \Joostvanveen\Litespeedcache\Cache);
foreach($uris as $uri) {
    $cache->cache('public', 120, $uri);
}
 
$excludedUris = [
    'checkout*',
    'admin*',
];
(new \Joostvanveen\Litespeedcache\Cache)->setExcludedUrls($excludedUris)->cache('public', 120);

(new Cache)->setEnableAjaxCache(true)->cache();

$requestTypes = ['GET', 'HEAD', 'POST', 'PUT'];
(new Cache)->setCacheableHttpVerbs($requestTypes)->cache();

$excludedQueryStrings = [
    '*direction=*',
];
(new \Joostvanveen\Litespeedcache\Cache)->setExcludedQueryStrings($excludedQueryStrings)->cache('public', 120);

(new \Joostvanveen\Litespeedcache\Cache)->addTags(['articles', 'english'])
                                        ->addTags(['page1'])
                                        ->cache('public', 120);

(new \Joostvanveen\Litespeedcache\Cache)->addVary('value=subdomain')->cache('public', 360);                            

(new \Joostvanveen\Litespeedcache\Cache)->addTags('articles')->cache('public', 120);

(new \Joostvanveen\Litespeedcache\Cache)->addUri('/about-us')
                                        ->purge();

(new \Joostvanveen\Litespeedcache\Cache)->addTags(['articles', 'english'])
                                        ->purge();

(new \Joostvanveen\Litespeedcache\Cache)->purgeTags(['articles', 'english']);

(new \Joostvanveen\Litespeedcache\Cache)->purgeTags('english');

(new \Joostvanveen\Litespeedcache\Cache)->purgeAll();

$cache = new \Joostvanveen\Litespeedcache\Cache; 

$cache->disable();
$enabled = $cache->enabled(); // Returns false

$cache->enable();
$enabled = $cache->enabled(); // Returns true

(new \Joostvanveen\Litespeedcache\Cache)->cache('public', 120);

use LitespeedCache;

[...]

LitespeedCache::cache('public', 120);

if(! \App::environment(‘testing’) {
    Cache::purge();
}