Skip to content

Commit

Permalink
Merge pull request PHPOffice#3857 from PHPOffice/powerkiki
Browse files Browse the repository at this point in the history
Restore PSR-16 Simple Cache v1 compatibility
  • Loading branch information
PowerKiKi authored Jan 4, 2024
2 parents a75022a + 63b9b97 commit 43481c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
30 changes: 8 additions & 22 deletions src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace PhpOffice\PhpSpreadsheet\Collection\Memory;

use DateInterval;
use Psr\SimpleCache\CacheInterface;

/**
* This is the default implementation for in-memory cell collection.
*
* Alternatives implementation should leverage off-memory, non-volatile storage
* Alternative implementation should leverage off-memory, non-volatile storage
* to reduce overall memory usage.
*/
class SimpleCache1 implements CacheInterface
Expand All @@ -25,14 +24,14 @@ public function clear(): bool
return true;
}

public function delete(string $key): bool
public function delete($key): bool
{
unset($this->cache[$key]);

return true;
}

public function deleteMultiple(iterable $keys): bool
public function deleteMultiple($keys): bool
{
foreach ($keys as $key) {
$this->delete($key);
Expand All @@ -41,10 +40,7 @@ public function deleteMultiple(iterable $keys): bool
return true;
}

/**
* @param mixed $default
*/
public function get(string $key, $default = null): mixed
public function get($key, $default = null): mixed
{
if ($this->has($key)) {
return $this->cache[$key];
Expand All @@ -53,10 +49,7 @@ public function get(string $key, $default = null): mixed
return $default;
}

/**
* @param mixed $default
*/
public function getMultiple(iterable $keys, $default = null): iterable
public function getMultiple($keys, $default = null): iterable
{
$results = [];
foreach ($keys as $key) {
Expand All @@ -66,26 +59,19 @@ public function getMultiple(iterable $keys, $default = null): iterable
return $results;
}

public function has(string $key): bool
public function has($key): bool
{
return array_key_exists($key, $this->cache);
}

/**
* @param mixed $value
* @param null|DateInterval|int $ttl
*/
public function set(string $key, $value, $ttl = null): bool
public function set($key, $value, $ttl = null): bool
{
$this->cache[$key] = $value;

return true;
}

/**
* @param null|DateInterval|int $ttl
*/
public function setMultiple(iterable $values, $ttl = null): bool
public function setMultiple($values, $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value);
Expand Down
26 changes: 5 additions & 21 deletions src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
/**
* This is the default implementation for in-memory cell collection.
*
* Alternatives implementation should leverage off-memory, non-volatile storage
* Alternative implementation should leverage off-memory, non-volatile storage
* to reduce overall memory usage.
*/
class SimpleCache3 implements CacheInterface
{
/**
* @var array Cell Cache
*/
private array $cache = [];

public function clear(): bool
Expand All @@ -41,10 +38,7 @@ public function deleteMultiple(iterable $keys): bool
return true;
}

/**
* @param mixed $default
*/
public function get(string $key, $default = null): mixed
public function get(string $key, mixed $default = null): mixed
{
if ($this->has($key)) {
return $this->cache[$key];
Expand All @@ -53,10 +47,7 @@ public function get(string $key, $default = null): mixed
return $default;
}

/**
* @param mixed $default
*/
public function getMultiple(iterable $keys, $default = null): iterable
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$results = [];
foreach ($keys as $key) {
Expand All @@ -71,21 +62,14 @@ public function has(string $key): bool
return array_key_exists($key, $this->cache);
}

/**
* @param mixed $value
* @param null|DateInterval|int $ttl
*/
public function set(string $key, $value, $ttl = null): bool
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
{
$this->cache[$key] = $value;

return true;
}

/**
* @param null|DateInterval|int $ttl
*/
public function setMultiple(iterable $values, $ttl = null): bool
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value);
Expand Down

0 comments on commit 43481c9

Please sign in to comment.