Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
AbstractAdapter | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTtl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getTtl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getItemTtl | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
saveItem | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getItem | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
hasItem | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
deleteItem | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
clear | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
destroy | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Cache\Adapter; |
15 | |
16 | /** |
17 | * Cache adapter abstract class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Cache |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.0.0 |
25 | */ |
26 | abstract class AbstractAdapter implements AdapterInterface |
27 | { |
28 | |
29 | /** |
30 | * Global time-to-live |
31 | * @var int |
32 | */ |
33 | protected int $ttl = 0; |
34 | |
35 | /** |
36 | * Constructor |
37 | * |
38 | * Instantiate the cache adapter object |
39 | * |
40 | * @param int $ttl |
41 | */ |
42 | public function __construct(int $ttl = 0) |
43 | { |
44 | $this->setTtl($ttl); |
45 | } |
46 | |
47 | /** |
48 | * Set the global time-to-live for the cache adapter |
49 | * |
50 | * @param int $ttl |
51 | * @return AbstractAdapter |
52 | */ |
53 | public function setTtl(int $ttl): AbstractAdapter |
54 | { |
55 | $this->ttl = $ttl; |
56 | return $this; |
57 | } |
58 | |
59 | /** |
60 | * Get the global time-to-live for the cache object |
61 | * |
62 | * @return int |
63 | */ |
64 | public function getTtl(): int |
65 | { |
66 | return $this->ttl; |
67 | } |
68 | |
69 | /** |
70 | * Get the time-to-live for an item in cache |
71 | * |
72 | * @param string $id |
73 | * @return int |
74 | */ |
75 | abstract public function getItemTtl(string $id): int; |
76 | |
77 | /** |
78 | * Save an item to cache |
79 | * |
80 | * @param string $id |
81 | * @param mixed $value |
82 | * @param ?int $ttl |
83 | * @return AbstractAdapter |
84 | */ |
85 | abstract public function saveItem(string $id, mixed $value, ?int $ttl = null): AbstractAdapter; |
86 | |
87 | /** |
88 | * Get an item from cache |
89 | * |
90 | * @param string $id |
91 | * @return mixed |
92 | */ |
93 | abstract public function getItem(string $id): mixed; |
94 | |
95 | /** |
96 | * Determine if the item exist in cache |
97 | * |
98 | * @param string $id |
99 | * @return bool |
100 | */ |
101 | abstract public function hasItem(string $id): bool; |
102 | |
103 | /** |
104 | * Delete a value in cache |
105 | * |
106 | * @param string $id |
107 | * @return AbstractAdapter |
108 | */ |
109 | abstract public function deleteItem(string $id): AbstractAdapter; |
110 | |
111 | /** |
112 | * Clear all stored values from cache |
113 | * |
114 | * @return AbstractAdapter |
115 | */ |
116 | abstract public function clear(): AbstractAdapter; |
117 | |
118 | /** |
119 | * Destroy cache resource |
120 | * |
121 | * @return AbstractAdapter |
122 | */ |
123 | abstract public function destroy(): AbstractAdapter; |
124 | |
125 | } |