CacheInterface.php
2 years ago
DoctrineBridge.php
2 years ago
LaravelCache.php
2 years ago
PSR16Bridge.php
2 years ago
PSR6Bridge.php
2 years ago
StaticCache.php
2 years ago
PSR6Bridge.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Device Detector - The Universal Device Detection library for parsing User Agents |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * |
| 8 | * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later |
| 9 | */ |
| 10 | declare (strict_types=1); |
| 11 | namespace IAWPSCOPED\DeviceDetector\Cache; |
| 12 | |
| 13 | use IAWPSCOPED\Psr\Cache\CacheItemPoolInterface; |
| 14 | /** @internal */ |
| 15 | class PSR6Bridge implements CacheInterface |
| 16 | { |
| 17 | /** |
| 18 | * @var CacheItemPoolInterface |
| 19 | */ |
| 20 | private $pool; |
| 21 | /** |
| 22 | * PSR6Bridge constructor. |
| 23 | * @param CacheItemPoolInterface $pool |
| 24 | */ |
| 25 | public function __construct(CacheItemPoolInterface $pool) |
| 26 | { |
| 27 | $this->pool = $pool; |
| 28 | } |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public function fetch(string $id) |
| 33 | { |
| 34 | $item = $this->pool->getItem($id); |
| 35 | return $item->isHit() ? $item->get() : \false; |
| 36 | } |
| 37 | /** |
| 38 | * @inheritDoc |
| 39 | */ |
| 40 | public function contains(string $id) : bool |
| 41 | { |
| 42 | return $this->pool->hasItem($id); |
| 43 | } |
| 44 | /** |
| 45 | * @inheritDoc |
| 46 | */ |
| 47 | public function save(string $id, $data, int $lifeTime = 0) : bool |
| 48 | { |
| 49 | $item = $this->pool->getItem($id); |
| 50 | $item->set($data); |
| 51 | if (\func_num_args() > 2) { |
| 52 | $item->expiresAfter($lifeTime); |
| 53 | } |
| 54 | return $this->pool->save($item); |
| 55 | } |
| 56 | /** |
| 57 | * @inheritDoc |
| 58 | */ |
| 59 | public function delete(string $id) : bool |
| 60 | { |
| 61 | return $this->pool->deleteItem($id); |
| 62 | } |
| 63 | /** |
| 64 | * @inheritDoc |
| 65 | */ |
| 66 | public function flushAll() : bool |
| 67 | { |
| 68 | return $this->pool->clear(); |
| 69 | } |
| 70 | } |
| 71 |