-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/initial-cache-implementation - refactor to psr/cache implemen…
…tation
- Loading branch information
Showing
9 changed files
with
361 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.