1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.8.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Cache; |
16
|
|
|
|
17
|
|
|
use Quantum\Exceptions\CacheException; |
18
|
|
|
use Psr\SimpleCache\CacheInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Cache |
22
|
|
|
* @package Quantum\Libraries\Cache |
23
|
|
|
* @method mixed get($key, $default = null) |
24
|
|
|
* @method array getMultiple($keys, $default = null) |
25
|
|
|
* @method has($key): bool |
26
|
|
|
* @method bool set($key, $value, $ttl = null) |
27
|
|
|
* @method bool setMultiple($values, $ttl = null) |
28
|
|
|
* @method bool delete($key) |
29
|
|
|
* @method bool deleteMultiple($keys) |
30
|
|
|
* @method bool clear() |
31
|
|
|
*/ |
32
|
|
|
class Cache |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Psr\SimpleCache\CacheInterface |
|
|
|
|
37
|
|
|
*/ |
38
|
|
|
private $adapter; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Cache constructor |
42
|
|
|
* @param Psr\SimpleCache\CacheInterface $cacheAdapter |
43
|
|
|
*/ |
44
|
|
|
public function __construct(CacheInterface $cacheAdapter) |
45
|
|
|
{ |
46
|
|
|
$this->adapter = $cacheAdapter; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Gets the current adapter |
51
|
|
|
* @return Psr\SimpleCache\CacheInterface |
52
|
|
|
*/ |
53
|
|
|
public function getAdapter(): CacheInterface |
54
|
|
|
{ |
55
|
|
|
return $this->adapter; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $method |
60
|
|
|
* @param array|null $arguments |
61
|
|
|
* @return mixed |
62
|
|
|
* @throws \Quantum\Exceptions\AppException |
63
|
|
|
*/ |
64
|
|
|
public function __call(string $method, ?array $arguments) |
65
|
|
|
{ |
66
|
|
|
if (!method_exists($this->adapter, $method)) { |
67
|
|
|
throw CacheException::methodNotSupported($method, get_class($this->adapter)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->adapter->$method(...$arguments); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|