Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"psr/simple-cache-implementation": "1.0"
},
"require": {
"php": ">=7.0.0",
"psr/simple-cache": "~1.0 || ~2.0"
"php": ">=8.0.0",
"psr/simple-cache": "~1.0 || ~2.0 || ~3.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"
Expand Down
50 changes: 7 additions & 43 deletions src/voku/cache/CachePsr16.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ public function clear(): bool
*
* @return bool True if the item was successfully removed. False if there was an error.
*/
public function delete($key): bool
public function delete(string $key): bool
{
if (!\is_string($key)) {
throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true));
}

return $this->removeItem($key);
}

Expand All @@ -46,16 +42,8 @@ public function delete($key): bool
*
* @return bool True if the items were successfully removed. False if there was an error.
*/
public function deleteMultiple($keys): bool
public function deleteMultiple(iterable $keys): bool
{
if (
!\is_array($keys)
&&
!($keys instanceof \Traversable)
) {
throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true));
}

$results = [];
foreach ((array) $keys as $key) {
$results[] = $this->delete($key);
Expand All @@ -74,7 +62,7 @@ public function deleteMultiple($keys): bool
*
* @return mixed the value of the item from the cache, or $default in case of cache miss
*/
public function get($key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
if ($this->has($key)) {
return $this->getItem($key);
Expand All @@ -94,16 +82,8 @@ public function get($key, $default = null)
* @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as
* value.
*/
public function getMultiple($keys, $default = null)
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
if (
!\is_array($keys)
&&
!($keys instanceof \Traversable)
) {
throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true));
}

$result = [];
foreach ((array) $keys as $key) {
$result[$key] = $this->has($key) ? $this->get($key) : $default;
Expand All @@ -126,12 +106,8 @@ public function getMultiple($keys, $default = null)
*
* @return bool
*/
public function has($key): bool
public function has(string $key): bool
{
if (!\is_string($key)) {
throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true));
}

return $this->existsItem($key);
}

Expand All @@ -148,12 +124,8 @@ public function has($key): bool
*
* @return bool true on success and false on failure
*/
public function set($key, $value, $ttl = null): bool
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
{
if (!\is_string($key)) {
throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true));
}

return $this->setItem($key, $value, $ttl);
}

Expand All @@ -169,16 +141,8 @@ public function set($key, $value, $ttl = null): bool
*
* @return bool true on success and false on failure
*/
public function setMultiple($values, $ttl = null): bool
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
{
if (
!\is_array($values)
&&
!($values instanceof \Traversable)
) {
throw new InvalidArgumentException('$values is not iterable:' . \print_r($values, true));
}

$results = [];
foreach ((array) $values as $key => $value) {
$results[] = $this->set($key, $value, $ttl);
Expand Down