diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php')
-rw-r--r-- | vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php b/vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php new file mode 100644 index 0000000..9824088 --- /dev/null +++ b/vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php | |||
@@ -0,0 +1,38 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Cache; | ||
6 | |||
7 | use function microtime; | ||
8 | |||
9 | class TimestampQueryCacheValidator implements QueryCacheValidator | ||
10 | { | ||
11 | public function __construct(private readonly TimestampRegion $timestampRegion) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | public function isValid(QueryCacheKey $key, QueryCacheEntry $entry): bool | ||
16 | { | ||
17 | if ($this->regionUpdated($key, $entry)) { | ||
18 | return false; | ||
19 | } | ||
20 | |||
21 | if ($key->lifetime === 0) { | ||
22 | return true; | ||
23 | } | ||
24 | |||
25 | return $entry->time + $key->lifetime > microtime(true); | ||
26 | } | ||
27 | |||
28 | private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry): bool | ||
29 | { | ||
30 | if ($key->timestampKey === null) { | ||
31 | return false; | ||
32 | } | ||
33 | |||
34 | $timestamp = $this->timestampRegion->get($key->timestampKey); | ||
35 | |||
36 | return $timestamp && $timestamp->time > $entry->time; | ||
37 | } | ||
38 | } | ||