PHP code example of davidecesarano / embryo-cache

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

    

davidecesarano / embryo-cache example snippets


use Embryo\Cache\Cache;
use Embryo\Http\Emitter\Emitter;
use Embryo\Http\Factory\ResponseFactory;

$emitter   = new Emitter;
$response  = (new ResponseFactory)->createResponse(200);
$cachePath = __DIR__.DIRECTORY_SEPARATOR.'cache';
$cache     = new Cache($cachePath);

if (!$cache->has('test')) {
    $cache->set('test', 'Hello World!', 3600);
}

$body = $response->getBody();
$body->write($cache->get('test', 'Default value!'));
$response = $response->withBody($body);

$emitter->emit($response);

$cache->get('key', 'default');

$cache->set('key', 'value', 3600);

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

$cache->getMultiple(['key1', 'key2'], 'default');

$cache->setMultiple([
    'key1' => 'value',
    'key2' => 'value'
], 3600);

$cache->deleteMultiple(['key1', 'key2']);

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