-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SimpleCache 2/3 compatible DevNullCache implementation
- Loading branch information
Showing
5 changed files
with
169 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scoutapm\Cache; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
use function array_combine; | ||
use function array_map; | ||
use function is_array; | ||
use function iterator_to_array; | ||
|
||
/** @internal */ | ||
abstract class DevNullCacheSimpleCache1 implements CacheInterface | ||
{ | ||
/** @inheritDoc */ | ||
public function get($key, $default = null) | ||
{ | ||
return $default; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function set($key, $value, $ttl = null): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function delete($key): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function clear(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function getMultiple($keys, $default = null) | ||
{ | ||
if (is_array($keys)) { | ||
$keysAsArray = $keys; | ||
} else { | ||
$keysAsArray = iterator_to_array($keys, false); | ||
} | ||
|
||
return array_combine( | ||
$keysAsArray, | ||
array_map( | ||
/** @return mixed */ | ||
function (string $key) use ($default) { | ||
return $this->get($key, $default); | ||
}, | ||
$keysAsArray | ||
) | ||
); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function setMultiple($values, $ttl = null): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function deleteMultiple($keys): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function has($key): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scoutapm\Cache; | ||
|
||
use DateInterval; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
use function array_combine; | ||
use function array_map; | ||
use function is_array; | ||
use function iterator_to_array; | ||
|
||
/** @internal */ | ||
abstract class DevNullCacheSimpleCache2And3 implements CacheInterface | ||
{ | ||
/** @inheritDoc */ | ||
public function get(string $key, mixed $default = null): mixed | ||
{ | ||
return $default; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function delete(string $key): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function clear(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function getMultiple(iterable $keys, mixed $default = null): iterable | ||
{ | ||
if (is_array($keys)) { | ||
$keysAsArray = $keys; | ||
} else { | ||
$keysAsArray = iterator_to_array($keys, false); | ||
} | ||
|
||
return array_combine( | ||
$keysAsArray, | ||
array_map( | ||
/** @return mixed */ | ||
function (string $key) use ($default) { | ||
return $this->get($key, $default); | ||
}, | ||
$keysAsArray | ||
) | ||
); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function deleteMultiple(iterable $keys): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function has(string $key): bool | ||
{ | ||
return false; | ||
} | ||
} |