2009-11-01 11:00:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Cache
|
2020-11-21 18:54:32 +00:00
|
|
|
{
|
|
|
|
public function set($id, $var)
|
2009-11-01 11:00:00 +00:00
|
|
|
{
|
2020-11-21 18:54:32 +00:00
|
|
|
$file = '<?php $cache = '.var_export($var, true).'; ?>';
|
2009-11-01 11:00:00 +00:00
|
|
|
|
2020-11-21 18:54:32 +00:00
|
|
|
file_put_contents(ONYX.'cache/'.md5($id).'.cache.php', $file) or trigger_error('dossier cache inaccessible en écriture.', E_USER_ERROR);
|
|
|
|
}
|
2009-11-01 11:00:00 +00:00
|
|
|
|
2020-11-21 18:54:32 +00:00
|
|
|
public function read($id)
|
|
|
|
{
|
|
|
|
if (!is_readable(ONYX.'cache/'.md5($id).'.cache.php')) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-01 11:00:00 +00:00
|
|
|
|
2020-11-21 18:54:32 +00:00
|
|
|
include(ONYX.'cache/'.md5($id).'.cache.php');
|
|
|
|
if (!$cache) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $cache;
|
|
|
|
}
|
2009-11-01 11:00:00 +00:00
|
|
|
|
2020-11-21 18:54:32 +00:00
|
|
|
public function del($id)
|
|
|
|
{
|
|
|
|
if (!is_file(ONYX.'cache/'.md5($id).'.cache.php')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return unlink(ONYX.'cache/'.md5($id).'.cache.php');
|
|
|
|
}
|
2009-11-01 11:00:00 +00:00
|
|
|
|
2020-11-21 18:54:32 +00:00
|
|
|
public function flush()
|
|
|
|
{
|
|
|
|
foreach (glob(ONYX.'cache/*.cache.php') as $file) {
|
|
|
|
unlink($file);
|
|
|
|
}
|
2009-11-01 11:00:00 +00:00
|
|
|
}
|
2020-11-21 18:54:32 +00:00
|
|
|
}
|