Skip to content

Commit

Permalink
Add helper for void cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SQKo committed Dec 3, 2023
1 parent 269e4e2 commit 12f4f1b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/Discord/Helpers/VoidCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* 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;
}
}

0 comments on commit 12f4f1b

Please sign in to comment.