2
2
3
3
namespace ByJG \Cache \Psr16 ;
4
4
5
+ use ByJG \Cache \Exception \InvalidArgumentException ;
5
6
use DateInterval ;
7
+ use Psr \Container \ContainerExceptionInterface ;
8
+ use Psr \Container \NotFoundExceptionInterface ;
9
+ use Psr \Log \LoggerInterface ;
6
10
use Psr \Log \NullLogger ;
7
11
8
12
class ArrayCacheEngine extends BaseCacheEngine
9
13
{
10
14
11
- protected $ cache = array () ;
15
+ protected array $ cache = [] ;
12
16
13
- protected $ logger = null ;
17
+ protected LoggerInterface | null $ logger = null ;
14
18
15
- public function __construct ($ logger = null )
19
+ public function __construct (LoggerInterface | null $ logger = null )
16
20
{
17
21
$ this ->logger = $ logger ;
18
22
if (is_null ($ logger )) {
@@ -29,10 +33,11 @@ public function __construct($logger = null)
29
33
*
30
34
* @param string $key The cache item key.
31
35
* @return bool
32
- * @throws \Psr\SimpleCache\InvalidArgumentException
33
- * MUST be thrown if the $key string is not a legal value.
36
+ * @throws InvalidArgumentException
37
+ * @throws ContainerExceptionInterface
38
+ * @throws NotFoundExceptionInterface
34
39
*/
35
- public function has ($ key )
40
+ public function has (string $ key ): bool
36
41
{
37
42
$ key = $ this ->getKeyFromContainer ($ key );
38
43
if (isset ($ this ->cache [$ key ])) {
@@ -51,9 +56,11 @@ public function has($key)
51
56
* @param string $key The object KEY
52
57
* @param mixed $default IGNORED IN MEMCACHED.
53
58
* @return mixed Description
54
- * @throws \Psr\SimpleCache\InvalidArgumentException
59
+ * @throws ContainerExceptionInterface
60
+ * @throws InvalidArgumentException
61
+ * @throws NotFoundExceptionInterface
55
62
*/
56
- public function get ($ key , $ default = null )
63
+ public function get (string $ key , mixed $ default = null ): mixed
57
64
{
58
65
if ($ this ->has ($ key )) {
59
66
$ key = $ this ->getKeyFromContainer ($ key );
@@ -78,7 +85,7 @@ public function get($key, $default = null)
78
85
*
79
86
* MUST be thrown if the $key string is not a legal value.
80
87
*/
81
- public function set ($ key , $ value , $ ttl = null )
88
+ public function set (string $ key , mixed $ value , DateInterval | int | null $ ttl = null ): bool
82
89
{
83
90
$ key = $ this ->getKeyFromContainer ($ key );
84
91
@@ -92,9 +99,10 @@ public function set($key, $value, $ttl = null)
92
99
return true ;
93
100
}
94
101
95
- public function clear ()
102
+ public function clear (): bool
96
103
{
97
104
$ this ->cache = [];
105
+ return true ;
98
106
}
99
107
100
108
/**
@@ -103,7 +111,7 @@ public function clear()
103
111
* @param string $key
104
112
* @return bool
105
113
*/
106
- public function delete ($ key )
114
+ public function delete (string $ key ): bool
107
115
{
108
116
$ key = $ this ->getKeyFromContainer ($ key );
109
117
@@ -112,7 +120,7 @@ public function delete($key)
112
120
return true ;
113
121
}
114
122
115
- public function isAvailable ()
123
+ public function isAvailable (): bool
116
124
{
117
125
return true ;
118
126
}
0 commit comments