Completed
Push — master ( ac2e46...b1f3f0 )
by Tomáš
01:19
created

RedisCache::doContains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Portiny\Doctrine\Cache;
5
6
use Doctrine\Common\Cache\RedisCache as DoctrineRedisCache;
7
8
final class RedisCache extends DoctrineRedisCache
9
{
10
	/**
11
	 * @var string[]
12
	 */
13
	private $prefetchCache = [];
14
15
	/**
16
	 * {@inheritdoc}
17
	 */
18
	protected function doContains($id): bool
19
	{
20
		// preload value into local variable becase Doctrine need it if TRUE is returned
21
		$value = $this->doFetch($id);
22
		$this->prefetchCache[$id] = $value;
23
24
		return $value !== FALSE;
25
	}
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30
	protected function doFetch($id)
31
	{
32
		// try load value from prefetch cache
33
		$doFetch = $this->prefetchCache[$id] ?? NULL;
34
		$this->prefetchCache = [];
35
36
		if ($doFetch === NULL) {
37
			$doFetch = parent::doFetch($id);
38
		}
39
40
		return $doFetch;
41
	}
42
}
43