Files
liche/common/vendor/gregwar/cache/Gregwar/Cache/demo/max-age.php
T
2022-08-29 08:47:22 +08:00

24 lines
724 B
PHP
Executable File

<?php
include('../autoload.php');
$cache = new Gregwar\Cache\Cache;
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "First call: generating file...\n";
return strtoupper(file_get_contents('original.txt'));
});
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "Second call: generating file, this should not happen!...\n";
return strtoupper(file_get_contents('original.txt'));
});
echo "Waiting 4s...\n";
sleep(4);
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "Third call: generating cache file, because it expired...\n";
return strtoupper(file_get_contents('original.txt'));
});