Skip to content

Commit 12f4f1b

Browse files
committed
Add helper for void cache
1 parent 269e4e2 commit 12f4f1b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/Discord/Helpers/VoidCache.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of the DiscordPHP project.
5+
*
6+
* Copyright (c) 2015-present David Cole <[email protected]>
7+
*
8+
* This file is subject to the MIT license that is bundled
9+
* with this source code in the LICENSE.md file.
10+
*/
11+
12+
namespace Discord\Helpers;
13+
14+
use Psr\SimpleCache\CacheInterface;
15+
16+
/**
17+
* The cache that always be null/void
18+
*/
19+
class VoidCache implements CacheInterface
20+
{
21+
public function get(string $key, mixed $default = null): mixed
22+
{
23+
return $default;
24+
}
25+
26+
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
27+
{
28+
return true;
29+
}
30+
31+
public function delete(string $key): bool
32+
{
33+
return true;
34+
}
35+
36+
public function getMultiple(iterable $keys, mixed $default = null): iterable
37+
{
38+
$result = [];
39+
40+
foreach ($keys as $key) {
41+
$result[$key] = $default;
42+
}
43+
44+
return $result;
45+
}
46+
47+
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool
48+
{
49+
return true;
50+
}
51+
52+
public function deleteMultiple(iterable $keys): bool
53+
{
54+
return true;
55+
}
56+
57+
public function clear(): bool
58+
{
59+
return true;
60+
}
61+
62+
public function has(string $key): bool
63+
{
64+
return false;
65+
}
66+
}

0 commit comments

Comments
 (0)