Friday release
This commit is contained in:
parent
10eb72688f
commit
c349769425
16 changed files with 319 additions and 89 deletions
|
|
@ -2,34 +2,45 @@
|
|||
|
||||
class Cache
|
||||
{
|
||||
|
||||
|
||||
static function set($id,$var)
|
||||
{
|
||||
$file = '<?php $cache = '.var_export($var,TRUE).'; ?>';
|
||||
|
||||
file_put_contents(ONYX.'cache/'.md5($id).'.cache.php',$file) or trigger_error('dossier cache inaccessible en écriture.',E_USER_ERROR);
|
||||
|
||||
$tmpfname = tempnam("/tmp", "cache");
|
||||
|
||||
if(file_put_contents($tmpfname, $file, LOCK_EX) !== FALSE)
|
||||
rename($tmpfname, ONYX.'cache/'.md5($id).'.cache.php') or trigger_error('dossier cache inaccessible en écriture.',E_USER_ERROR);
|
||||
else
|
||||
trigger_error('impossible d\'?crire dans '.$tmpfname,E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
static function read($id)
|
||||
{
|
||||
if(!is_readable(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
|
||||
include(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
if(!$cache) return FALSE;
|
||||
|
||||
$tmpfname = tempnam("/tmp", "cache");
|
||||
copy(ONYX.'cache/'.md5($id).'.cache.php', $tmpfname);
|
||||
|
||||
include($tmpfname);
|
||||
|
||||
unlink($tmpfname);
|
||||
|
||||
if(empty($cache)) return FALSE;
|
||||
return $cache;
|
||||
}
|
||||
|
||||
|
||||
static function del($id)
|
||||
{
|
||||
if(!is_file(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
return unlink(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
}
|
||||
|
||||
|
||||
static function flush()
|
||||
{
|
||||
foreach(glob(ONYX.'cache/*.cache.php') as $file) unlink($file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in a new issue