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

RedisCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 35
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doContains() 0 8 1
A doFetch() 0 12 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