file-cache
file-cache copied to clipboard
Create cache based on custom timestamp
Save data with lifetime 0 to make it valid forever, and check against custom timestamp with get. e.g.
// some function which generates data
function getData()
{
return array(
'name' => 'John',
'age' => 20,
'sex' => 'f');
}
// a timestamp which indicates if the data changed
$timestamp = filemtime(__FILE__);
// Get data from cache if cache is newer than timestamp
$user = $cache->get($id, $timestamp);
// If cache is expired or does not exist, re-generate data and store in cache
if(!$user)
{
$user = getData();
$cache->save($id, $user, 0);
}