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