game/onyx2/require/cache.php
Nigel dd61d3b66b
All checks were successful
continuous-integration/drone/push Build is passing
Ajout d'une étape de linting dans DroneCi (#3)
Corrige un doublons laissé par le rebase semi-manuel

Ajout d'une étape de linting dans DroneCi

Fix linting

Co-authored-by: Nigel Sheldon <nigelsheldon@live.fr>
Reviewed-on: https://gitea.nemunai.re/halo-battle/game/pulls/3
2020-11-21 18:54:32 +00:00

40 lines
956 B
PHP

<?php
class Cache
{
public 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);
}
public 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;
}
return $cache;
}
public function del($id)
{
if (!is_file(ONYX.'cache/'.md5($id).'.cache.php')) {
return false;
}
return unlink(ONYX.'cache/'.md5($id).'.cache.php');
}
public function flush()
{
foreach (glob(ONYX.'cache/*.cache.php') as $file) {
unlink($file);
}
}
}