-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCacheItem.php
More file actions
76 lines (57 loc) · 1.39 KB
/
CacheItem.php
File metadata and controls
76 lines (57 loc) · 1.39 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace PhpSpellcheck\Cache;
use DateInterval;
use DateTimeInterface;
use Psr\Cache\CacheItemInterface;
final class CacheItem implements CacheItemInterface
{
public function __construct(
private readonly string $key,
private mixed $value = null,
public ?DateTimeInterface $expiry = null,
private bool $isHit = false
) {
}
public function getKey(): string
{
return $this->key;
}
public function get(): mixed
{
return $this->value;
}
public function isHit(): bool
{
return $this->isHit;
}
public function set(mixed $value): static
{
$this->value = $value;
return $this;
}
public function expiresAt(?DateTimeInterface $expiration): static
{
$this->expiry = $expiration;
return $this;
}
public function expiresAfter(DateInterval|int|null $time): static
{
if ($time === null) {
$this->expiry = null;
return $this;
}
if (\is_int($time)) {
$this->expiry = new \DateTime('@' . (time() + $time));
return $this;
}
$datetime = new \DateTime();
$datetime->add($time);
$this->expiry = $datetime;
return $this;
}
public function setIsHit(bool $hit): void
{
$this->isHit = $hit;
}
}