1 | <?php |
||
7 | class CacheManager { |
||
8 | /** @var string **/ |
||
9 | protected $defaultDriver = 'memory'; |
||
10 | /** @var array **/ |
||
11 | protected $pools; |
||
12 | /** @var array **/ |
||
13 | protected $options; |
||
14 | |||
15 | /** |
||
16 | * @param array $options |
||
17 | */ |
||
18 | 7 | public function __construct($options = []) { |
|
19 | 7 | $this->options = $options; |
|
20 | 7 | } |
|
21 | |||
22 | /** |
||
23 | * @param \Psr\Cache\CacheItemInterface $item |
||
24 | */ |
||
25 | 2 | public function save(CacheItemInterface $item) { |
|
28 | |||
29 | /** |
||
30 | * @param string $key |
||
31 | * @param string $driver |
||
32 | * @param int $ttl |
||
33 | * @return \Psr\Cache\CacheItemInterface |
||
34 | */ |
||
35 | public function getItem($key, $driver = null, $ttl = null) { |
||
36 | $finalDriver = ($driver !== null) ? $driver : $this->defaultDriver; |
||
37 | |||
38 | $pool = $this->getItemPool($finalDriver); |
||
39 | $item = $pool->getItem($key); |
||
40 | |||
41 | // In this case, the pool returned a new CacheItem |
||
42 | if($item->get() === null) { |
||
|
|||
43 | $item->expiresAfter($ttl); |
||
44 | } |
||
45 | return $item; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * |
||
50 | * @param string $driver |
||
51 | * @return Psr\Cache\CacheItemPoolInterface |
||
52 | */ |
||
53 | 3 | public function getItemPool($driver) { |
|
60 | } |
||
61 |