summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Cache/TimestampQueryCacheValidator.php
diff options
context:
space:
mode:
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}