CacheInterface.php
1 year ago
DoctrineBridge.php
1 year ago
LaravelCache.php
1 year ago
PSR16Bridge.php
1 year ago
PSR6Bridge.php
1 year ago
StaticCache.php
1 year ago
PSR6Bridge.php
82 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 | |
| 11 | declare(strict_types=1); |
| 12 | |
| 13 | namespace DeviceDetector\Cache; |
| 14 | |
| 15 | use Psr\Cache\CacheItemPoolInterface; |
| 16 | |
| 17 | class PSR6Bridge implements CacheInterface |
| 18 | { |
| 19 | /** |
| 20 | * @var CacheItemPoolInterface |
| 21 | */ |
| 22 | private $pool; |
| 23 | |
| 24 | /** |
| 25 | * PSR6Bridge constructor. |
| 26 | * @param CacheItemPoolInterface $pool |
| 27 | */ |
| 28 | public function __construct(CacheItemPoolInterface $pool) |
| 29 | { |
| 30 | $this->pool = $pool; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @inheritDoc |
| 35 | */ |
| 36 | public function fetch(string $id) |
| 37 | { |
| 38 | $item = $this->pool->getItem($id); |
| 39 | |
| 40 | return $item->isHit() ? $item->get() : false; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @inheritDoc |
| 45 | */ |
| 46 | public function contains(string $id): bool |
| 47 | { |
| 48 | return $this->pool->hasItem($id); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @inheritDoc |
| 53 | */ |
| 54 | public function save(string $id, $data, int $lifeTime = 0): bool |
| 55 | { |
| 56 | $item = $this->pool->getItem($id); |
| 57 | $item->set($data); |
| 58 | |
| 59 | if (\func_num_args() > 2) { |
| 60 | $item->expiresAfter($lifeTime); |
| 61 | } |
| 62 | |
| 63 | return $this->pool->save($item); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @inheritDoc |
| 68 | */ |
| 69 | public function delete(string $id): bool |
| 70 | { |
| 71 | return $this->pool->deleteItem($id); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @inheritDoc |
| 76 | */ |
| 77 | public function flushAll(): bool |
| 78 | { |
| 79 | return $this->pool->clear(); |
| 80 | } |
| 81 | } |
| 82 |