game/onyx2/require/cache.php

40 lines
956 B
PHP
Raw Normal View History

2009-11-01 11:00:00 +00:00
<?php
class Cache
{
public function set($id, $var)
2009-11-01 11:00:00 +00:00
{
$file = '<?php $cache = '.var_export($var, true).'; ?>';
2009-11-01 11:00:00 +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
public function read($id)
{
if (!is_readable(ONYX.'cache/'.md5($id).'.cache.php')) {
return false;
}
2009-11-01 11:00:00 +00:00
include(ONYX.'cache/'.md5($id).'.cache.php');
if (!$cache) {
return false;
}
return $cache;
}
2009-11-01 11:00:00 +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
public function flush()
{
foreach (glob(ONYX.'cache/*.cache.php') as $file) {
unlink($file);
}
2009-11-01 11:00:00 +00:00
}
}