From 17f924d3630c3123626363c5121c18e4f7adbba4 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:05:44 +0700 Subject: [PATCH] Add helper for void cache --- src/Discord/Helpers/VoidCache.php | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Discord/Helpers/VoidCache.php diff --git a/src/Discord/Helpers/VoidCache.php b/src/Discord/Helpers/VoidCache.php new file mode 100644 index 000000000..282bb5b59 --- /dev/null +++ b/src/Discord/Helpers/VoidCache.php @@ -0,0 +1,66 @@ + + * + * This file is subject to the MIT license that is bundled + * with this source code in the LICENSE.md file. + */ + +namespace Discord\Helpers; + +use Psr\SimpleCache\CacheInterface; + +/** + * The cache that always be null/void + */ +class VoidCache implements CacheInterface +{ + public function get(string $key, mixed $default = null): mixed + { + return $default; + } + + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool + { + return true; + } + + public function delete(string $key): bool + { + return true; + } + + public function getMultiple(iterable $keys, mixed $default = null): iterable + { + $result = []; + + foreach ($keys as $key) { + $result[$key] = $default; + } + + return $result; + } + + public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool + { + return true; + } + + public function deleteMultiple(iterable $keys): bool + { + return true; + } + + public function clear(): bool + { + return true; + } + + public function has(string $key): bool + { + return false; + } +}