PHP code example of phant / cache

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

    

phant / cache example snippets


use Phant\Cache\File as CacheFile;

$cache = new CacheFile('path/cache/', 'my-cache-container', CacheFile::TTL_HOUR);

use Phant\Cache\Runtime as CacheRuntime;

$cache = new CacheRuntime();

$val = $cache->getOrSet(
	'my-key',
	function () {
		return 'my-val';
	},
	$cache::TTL_HOUR
);

if ($cache->has('my-key')) {
	
}

$cache->set('my-key', 'my-val', $cache::TTL_HOUR);

$val = $cache->get('my-key');

$cache->delete('my-key');

$cache->setMultiple([
	'my-key-1' => 'val-1',
	'my-key-2' => 'val-2',
	'my-key-3' => 'val-3',
], $cache::TTL_HOUR);

foreach ($cache->getMultiple([
	'my-key-1',
	'my-key-2',
	'my-key-3',
]) as $val) {

}

$cache->deleteMultiple([
	'my-key-1',
	'my-key-2',
	'my-key-3',
]);

$cache->clear();