Completed
Push — master ( 99d075...0c659c )
by Pavel
26:03
created

LoggingCache::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
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