Simple-PHP-Cache icon indicating copy to clipboard operation
Simple-PHP-Cache copied to clipboard

expiration time not working !

Open indiarocks08 opened this issue 9 years ago • 1 comments

i Created a php file and run this code to grab a json and store in .cache file, Everytime i refresh the php page, cache is also refreshed,

So Now shall I read the json data from the php file or from the .cache file to save api limits ?

indiarocks08 avatar Apr 30 '15 05:04 indiarocks08

You have to create something like this.

//Include Cache
require_once 'includes/cache.class.php';

//Create the cache
$cache = new Cache(array(
  'name'      => 'mycache',
  'path'      => 'cache/',
  'extension' => '.cache'
));

$cache->eraseExpired();
if($cache->isCached("hello") === false){
    echo("Save in cache -> hello <br>");
    $cache->store('hello', 'Hello World!', 60); //60 Seconds
}
else{
    echo("Read to cache -> hello <br>");
}
if($cache->isCached("test") === false){
    echo("Save in cache -> test <br>");
    $cache->store('test', 'Hello test!', 45); //45 Seconds
}
else{
    echo("Read to cache -> test <br>");
}

mtreik avatar Jul 06 '16 08:07 mtreik