Use single file for storing cache information.
This commit is contained in:
parent
cba344e4a4
commit
15d5eaec22
1 changed files with 5 additions and 8 deletions
|
@ -14,25 +14,22 @@ $dataSources = array(
|
||||||
'steam' => 3600,
|
'steam' => 3600,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$cacheData = json_decode(file_get_contents('../data/cache.txt'),true);
|
||||||
$sourceData = json_decode(file_get_contents('../data/index.txt'),true);
|
$sourceData = json_decode(file_get_contents('../data/index.txt'),true);
|
||||||
foreach($dataSources as $dataSource=>$refreshTime) {
|
foreach($dataSources as $dataSource=>$refreshTime) {
|
||||||
$file = sprintf('../cache/%s.txt', $dataSource);
|
|
||||||
// check last time the data was updated
|
// check last time the data was updated
|
||||||
if(file_exists($file)) {
|
$lastModified = (array_key_exists($dataSource, $cacheData)) ?
|
||||||
$lastModified = filemtime($file);
|
$cacheData[$dataSource] : 0;
|
||||||
} else {
|
|
||||||
$lastModified = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and see if we need to retrieve new information
|
// and see if we need to retrieve new information
|
||||||
if(time() - $lastModified > $refreshTime) {
|
if(time() - $lastModified > $refreshTime) {
|
||||||
file_put_contents($file,time());
|
$cacheData[$dataSource] = time();
|
||||||
|
|
||||||
$sourceData[$dataSource] = call_user_func($dataSource);
|
$sourceData[$dataSource] = call_user_func($dataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_r($sourceData);
|
file_put_contents('../data/cache.txt',json_encode($cacheData));
|
||||||
file_put_contents('../data/index.txt',json_encode($sourceData));
|
file_put_contents('../data/index.txt',json_encode($sourceData));
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue