-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOpenapiArrayCache.php
More file actions
46 lines (35 loc) · 923 Bytes
/
OpenapiArrayCache.php
File metadata and controls
46 lines (35 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Openapi\Cache;
class OpenapiArrayCache implements OpenapiCacheInterface
{
private array $cache = [];
private array $expiry = [];
public function get(string $key): mixed
{
if (!isset($this->cache[$key])) {
return null;
}
if (isset($this->expiry[$key]) && time() > $this->expiry[$key]) {
$this->delete($key);
return null;
}
return $this->cache[$key];
}
public function save(string $key, mixed $value, int $ttl = 3600): bool
{
$this->cache[$key] = $value;
$this->expiry[$key] = time() + $ttl;
return true;
}
public function delete(string $key): bool
{
unset($this->cache[$key], $this->expiry[$key]);
return true;
}
public function clear(): bool
{
$this->cache = [];
$this->expiry = [];
return true;
}
}