1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Doctrine\Cache; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\Doctrine\EntityDataCacheInterface; |
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
use Psr\Log\NullLogger; |
8
|
|
|
|
9
|
|
|
final class LoggingCache implements EntityDataCacheInterface |
10
|
|
|
{ |
11
|
|
|
/** @var EntityDataCacheInterface */ |
12
|
|
|
private $delegate; |
13
|
|
|
/** @var LoggerInterface */ |
14
|
|
|
private $logger; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* LoggingCache constructor. |
18
|
|
|
* |
19
|
|
|
* @param EntityDataCacheInterface $delegate |
20
|
|
|
* @param LoggerInterface $logger |
21
|
|
|
*/ |
22
|
1 |
|
public function __construct(EntityDataCacheInterface $delegate, LoggerInterface $logger = null) |
23
|
|
|
{ |
24
|
1 |
|
$this->delegate = $delegate; |
25
|
1 |
|
$this->logger = $logger ?: new NullLogger(); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
1 |
|
public function get(array $identifier) |
30
|
|
|
{ |
31
|
1 |
|
$data = $this->delegate->get($identifier); |
32
|
|
|
|
33
|
1 |
|
$this->logger->debug( |
34
|
1 |
|
sprintf('Entity cache %s', null === $data ? 'HIT' : 'MISS'), |
35
|
1 |
|
['class' => $this->getMetadata()->getName(), 'identifiers' => $identifier] |
36
|
1 |
|
); |
37
|
|
|
|
38
|
1 |
|
return $data; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** {@inheritdoc} */ |
42
|
1 |
|
public function set(array $identifier, $data) |
43
|
|
|
{ |
44
|
1 |
|
$this->delegate->set($identifier, $data); |
45
|
|
|
|
46
|
1 |
|
$this->logger->debug( |
47
|
1 |
|
'Stored API entity data to cache', |
48
|
1 |
|
['class' => $this->getMetadata()->getName(), 'identifiers' => $identifier] |
49
|
1 |
|
); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** {@inheritdoc} */ |
53
|
1 |
|
public function getMetadata() |
54
|
|
|
{ |
55
|
1 |
|
return $this->delegate->getMetadata(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** {@inheritdoc} */ |
59
|
|
|
public function getConfiguration() |
60
|
|
|
{ |
61
|
|
|
return $this->delegate->getConfiguration(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** {@inheritdoc} */ |
65
|
|
|
public function clear(array $identifier) |
66
|
|
|
{ |
67
|
|
|
$this->delegate->clear($identifier); |
68
|
|
|
|
69
|
|
|
$this->logger->debug( |
70
|
|
|
'Cleared API entity data from cache', |
71
|
|
|
['class' => $this->getMetadata()->getName(), 'identifiers' => $identifier] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|