Passed
Push — master ( 158252...631a8c )
by Maxim
02:44
created

CacheService::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace WebComplete\core\utils\cache;
4
5
use Psr\Cache\CacheItemPoolInterface;
6
use Psr\SimpleCache\CacheInterface;
7
use Symfony\Component\Cache\Adapter\AdapterInterface;
8
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
9
use Symfony\Component\Cache\Simple\Psr6Cache;
10
11
class CacheService
12
{
13
    /**
14
     * @var CacheItemPoolInterface
15
     */
16
    protected $systemCache;
17
    /**
18
     * @var CacheItemPoolInterface
19
     */
20
    protected $userCache;
21
    /**
22
     * @var CacheInterface
23
     */
24
    protected $systemCacheSimple;
25
    /**
26
     * @var CacheInterface
27
     */
28
    protected $userCacheSimple;
29
30
    /**
31
     * @param CacheItemPoolInterface $systemCache
32
     * @param CacheItemPoolInterface $userCache
33
     */
34
    public function __construct(CacheItemPoolInterface $systemCache, CacheItemPoolInterface $userCache)
35
    {
36
        $this->systemCache = $systemCache;
37
        $this->userCache = $userCache instanceof AdapterInterface
38
            ? new TagAwareAdapter($userCache, $userCache)
39
            : $userCache;
40
    }
41
42
    /**
43
     * @return CacheItemPoolInterface
44
     */
45
    public function system(): CacheItemPoolInterface
46
    {
47
        return $this->systemCache;
48
    }
49
50
    /**
51
     * @return CacheItemPoolInterface
52
     */
53
    public function user(): CacheItemPoolInterface
54
    {
55
        return $this->userCache;
56
    }
57
58
    /**
59
     * @return CacheInterface
60
     */
61
    public function systemSimple(): CacheInterface
62
    {
63
        if (!$this->systemCacheSimple) {
64
            $this->systemCacheSimple = new Psr6Cache($this->systemCache);
65
        }
66
        return $this->systemCacheSimple;
67
    }
68
69
    /**
70
     * @return CacheInterface
71
     */
72
    public function userSimple(): CacheInterface
73
    {
74
        if (!$this->userCacheSimple) {
75
            $this->userCacheSimple = new Psr6Cache($this->userCache);
76
        }
77
        return $this->userCacheSimple;
78
    }
79
}
80