blob: 2037f271788504cdde0166a92a95dcb9c3bd6879 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php
namespace Core;
class FileCache extends Cache
{
const CACHE_FOLDER = 'data/cache/';
public function init()
{
if (! is_dir(self::CACHE_FOLDER)) {
mkdir(self::CACHE_FOLDER);
}
}
public function set($key, $value)
{
file_put_contents(self::CACHE_FOLDER.$key, json_encode($value));
}
public function get($key)
{
if (file_exists(self::CACHE_FOLDER.$key)) {
return json_decode(file_get_contents(self::CACHE_FOLDER.$key), true);
}
return null;
}
public function flush()
{
foreach (glob(self::CACHE_FOLDER.'*') as $filename) {
@unlink($filename);
}
}
public function remove($key)
{
@unlink(self::CACHE_FOLDER.$key);
}
}
|