Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1014 Bytes

06-caching.md

File metadata and controls

41 lines (29 loc) · 1014 Bytes

Caching

Embera provides a simple caching interface in order to reduce server load requesting information to the providers. The engine is a simple file cache, so you need to add a writable folder.

To enable it use the following code as an example:

use Embera\Cache\Filesystem;
use Embera\Http\HttpClient;
use Embera\Http\HttpClientCache;
use Embera\Embera;

$writablePath = sys_get_temp_dir(); // Your writable Path
$duration = 60; // Duration of the cache in seconds

$httpCache = new HttpClientCache(new HttpClient());
$httpCache->setCachingEngine(new Filesystem($writablePath, $duration));

// Instantiate Embera
$embera = new Embera([], null, $httpCache);

// Do Your thing

Cache Flushing

use Embera\Cache\Filesystem;
use Embera\Http\HttpClient;
use Embera\Http\HttpClientCache;
use Embera\Embera;

$writablePath = sys_get_temp_dir(); // Your writable Path
$duration = 60; // Duration of the cache in seconds
$cache = new Filesystem($writablePath, $duration);
$cache->clear();