|
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
|
|
|
|