/
SimpleCache.php
77 lines (63 loc) · 1.79 KB
/
SimpleCache.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Created by PhpStorm.
* User: ice
* Email: xykxyk2008@163.com
* Date: 2021/4/17
* Time: 12:04 上午
*/
namespace EasySwoole\Skeleton\Component\Cache;
use EasySwoole\Skeleton\Component\Cache\Driver\FileDriver;
use EasySwoole\Skeleton\Component\Cache\Packer\PhpSerializerPacker;
use Psr\SimpleCache\CacheInterface;
class SimpleCache implements CacheInterface
{
protected $driver;
public function __construct()
{
$cache = config('cache');
$driver = $cache['driver'] ?? FileDriver::class;
$packer = $cache['packer'] ?? PhpSerializerPacker::class;
$this->driver = new $driver([
'packer' => $packer,
'prefix' => $cache['prefix'] ?? 'c:',
'dir' => $cache['dir'] ?? null,
]);
}
public function __call($name, $arguments)
{
return $this->driver->{$name}(...$arguments);
}
public function get($key, $default = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function set($key, $value, $ttl = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function delete($key)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function clear()
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function getMultiple($keys, $default = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function setMultiple($values, $ttl = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function deleteMultiple($keys)
{
return $this->__call(__FUNCTION__, func_get_args());
}
public function has($key)
{
return $this->__call(__FUNCTION__, func_get_args());
}
}