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
11declare(strict_types=1);
12
13namespace DeviceDetector\Cache;
14
15use Psr\SimpleCache\CacheInterface as PsrCacheInterface;
16
17class PSR16Bridge implements CacheInterface
18{
19    /**
20     * @var PsrCacheInterface
21     */
22    private $cache;
23
24    /**
25     * PSR16Bridge constructor.
26     * @param PsrCacheInterface $cache
27     */
28    public function __construct(PsrCacheInterface $cache)
29    {
30        $this->cache = $cache;
31    }
32
33    /**
34     * @inheritDoc
35     */
36    public function fetch(string $id)
37    {
38        return $this->cache->get($id, false);
39    }
40
41    /**
42     * @inheritDoc
43     */
44    public function contains(string $id): bool
45    {
46        return $this->cache->has($id);
47    }
48
49    /**
50     * @inheritDoc
51     */
52    public function save(string $id, $data, int $lifeTime = 0): bool
53    {
54        return $this->cache->set($id, $data, \func_num_args() < 3 ? null : $lifeTime);
55    }
56
57    /**
58     * @inheritDoc
59     */
60    public function delete(string $id): bool
61    {
62        return $this->cache->delete($id);
63    }
64
65    /**
66     * @inheritDoc
67     */
68    public function flushAll(): bool
69    {
70        return $this->cache->clear();
71    }
72}
73