PHP code example of laurent22 / kache

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

    

laurent22 / kache example snippets


Kache::setup(array(
	'driver' => 'file',
	'path' => '/path/to/cache_folder',
));

Kache::setup(array(
	'driver' => 'redis',
	'server' => array(
		'host' => '127.0.0.1',
		'port' => 6379,
		'dbindex' => 1,
	),
));

Kache::setup(array(
	'driver' => 'null',
));

k()->set('somekey', 'somevalue', 120); // Cache for 2 minutes
var_dump(k()->get('somekey'));
$k()->delete('somekey');

function getName() {
	$name = k()->get('name');
	if ($name !== null) return $name;
	$name = getNameFromDb();
	k()->set('name', $name, 600);
	return $name;
}

function getName() {
	return k()->getOrRun('name', function() {
		return getNameFromDb();
	}, 600);
}