22
33namespace ByJG \Cache \Psr16 ;
44
5+ use ByJG \Cache \Exception \InvalidArgumentException ;
56use DateInterval ;
7+ use Psr \Container \ContainerExceptionInterface ;
8+ use Psr \Container \NotFoundExceptionInterface ;
9+ use Psr \Log \LoggerInterface ;
610use Psr \Log \NullLogger ;
711
812class ArrayCacheEngine extends BaseCacheEngine
913{
1014
11- protected $ cache = array () ;
15+ protected array $ cache = [] ;
1216
13- protected $ logger = null ;
17+ protected LoggerInterface | null $ logger = null ;
1418
15- public function __construct ($ logger = null )
19+ public function __construct (LoggerInterface | null $ logger = null )
1620 {
1721 $ this ->logger = $ logger ;
1822 if (is_null ($ logger )) {
@@ -29,10 +33,11 @@ public function __construct($logger = null)
2933 *
3034 * @param string $key The cache item key.
3135 * @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
3439 */
35- public function has ($ key )
40+ public function has (string $ key ): bool
3641 {
3742 $ key = $ this ->getKeyFromContainer ($ key );
3843 if (isset ($ this ->cache [$ key ])) {
@@ -51,9 +56,11 @@ public function has($key)
5156 * @param string $key The object KEY
5257 * @param mixed $default IGNORED IN MEMCACHED.
5358 * @return mixed Description
54- * @throws \Psr\SimpleCache\InvalidArgumentException
59+ * @throws ContainerExceptionInterface
60+ * @throws InvalidArgumentException
61+ * @throws NotFoundExceptionInterface
5562 */
56- public function get ($ key , $ default = null )
63+ public function get (string $ key , mixed $ default = null ): mixed
5764 {
5865 if ($ this ->has ($ key )) {
5966 $ key = $ this ->getKeyFromContainer ($ key );
@@ -78,7 +85,7 @@ public function get($key, $default = null)
7885 *
7986 * MUST be thrown if the $key string is not a legal value.
8087 */
81- public function set ($ key , $ value , $ ttl = null )
88+ public function set (string $ key , mixed $ value , DateInterval | int | null $ ttl = null ): bool
8289 {
8390 $ key = $ this ->getKeyFromContainer ($ key );
8491
@@ -92,9 +99,10 @@ public function set($key, $value, $ttl = null)
9299 return true ;
93100 }
94101
95- public function clear ()
102+ public function clear (): bool
96103 {
97104 $ this ->cache = [];
105+ return true ;
98106 }
99107
100108 /**
@@ -103,7 +111,7 @@ public function clear()
103111 * @param string $key
104112 * @return bool
105113 */
106- public function delete ($ key )
114+ public function delete (string $ key ): bool
107115 {
108116 $ key = $ this ->getKeyFromContainer ($ key );
109117
@@ -112,7 +120,7 @@ public function delete($key)
112120 return true ;
113121 }
114122
115- public function isAvailable ()
123+ public function isAvailable (): bool
116124 {
117125 return true ;
118126 }
0 commit comments