summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-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.php38
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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Cache;
6
7use function microtime;
8
9class 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}