knot-lib/cache

View on GitHub
demo/04_clear.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
require_once __DIR__ . '/../vendor/autoload.php';

use Psr\SimpleCache\CacheException;

use knotlib\cache\FileCache;

try{
    $config = require_once(__DIR__ . '/include/config_file_cache.inc.php');
    $cache = new FileCache($config);

    $cache->set('my favorite artist', 'stevie wonder');
    $cache->set('my favorite movie', 'Jurassic Park');

    echo 'my favorite artist: ' . $cache->get('my favorite artist') . PHP_EOL;
    echo 'my favorite movie: ' . $cache->get('my favorite movie') . PHP_EOL;

    $cache->clear();

    echo 'my favorite artist: ' . $cache->get('my favorite artist') . PHP_EOL;
    echo 'my favorite movie: ' . $cache->get('my favorite movie') . PHP_EOL;
}
catch(CacheException $e)
{
    echo $e->getTraceAsString();
}
catch(Throwable $e)
{
    echo $e->getTraceAsString();
}