Skip to content

PhantPHP/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cache

Requirments

PHP >= 8.1

Install

composer require phant/cache

Usages

Phant Cache implement the PSR-16 SimpleCache interface : Psr\SimpleCache\CacheInterface

Init cache

File

Store cache in file.

use Phant\Cache\File as CacheFile;

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

Runtime

Store cache in runtime memory.

use Phant\Cache\Runtime as CacheRuntime;

$cache = new CacheRuntime();

Get or set

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

Has (PSR-16 SimpleCache)

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

Set (PSR-16 SimpleCache)

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

Get (PSR-16 SimpleCache)

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

Delete (PSR-16 SimpleCache)

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

Set multiple (PSR-16 SimpleCache)

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

Get multiple (PSR-16 SimpleCache)

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

}

Delete multiple (PSR-16 SimpleCache)

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

Clear (PSR-16 SimpleCache)

$cache->clear();