Completed
Push — master ( 283745...8baa4f )
by André
49:49 queued 25:19
created

InMemoryClearingProxyAdapter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 113
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getItem() 0 4 1
A getItems() 0 4 1
A hasItem() 0 4 1
A deleteItem() 0 6 1
A deleteItems() 0 6 1
A invalidateTags() 0 7 1
A clear() 0 6 1
A save() 0 4 1
A saveDeferred() 0 4 1
A commit() 0 4 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Cache\Adapter;
10
11
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
12
use eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache;
13
use Psr\Cache\CacheItemInterface;
14
15
/**
16
 * Internal proxy adapter to make sure to clear in-memory cache when needed.
17
 *
18
 * @intenral For type hinting inside eZ\Publish\Core\Persistence\Cache\*. For external, type hint on TagAwareAdapterInterface.
19
 */
20
class InMemoryClearingProxyAdapter implements TagAwareAdapterInterface
21
{
22
    /**
23
     * @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface
24
     */
25
    private $pool;
26
27
    /**
28
     * @var \eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache
29
     */
30
    private $inMemory;
31
32
    /**
33
     * InMemoryClearingProxyAdapter constructor.
34
     *
35
     * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $pool
36
     * @param \eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache $inMemory
37
     */
38
    public function __construct(TagAwareAdapterInterface $pool, InMemoryCache $inMemory)
39
    {
40
        $this->pool = $pool;
41
        $this->inMemory = $inMemory;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getItem($key)
48
    {
49
        return $this->pool->getItem($key);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getItems(array $keys = [])
56
    {
57
        return $this->pool->getItems($keys);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function hasItem($key)
64
    {
65
        return $this->pool->hasItem($key);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function deleteItem($key)
72
    {
73
        $this->inMemory->deleteMulti([$key]);
74
75
        return $this->pool->deleteItem($key);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function deleteItems(array $keys)
82
    {
83
        $this->inMemory->deleteMulti($keys);
84
85
        return $this->pool->deleteItems($keys);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function invalidateTags(array $tags)
92
    {
93
        // No tracking of tags in in-memory, as it's anyway meant to only optimize for reads (GETs) and not writes.
94
        $this->inMemory->clear();
95
96
        return $this->pool->invalidateTags($tags);
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function clear()
103
    {
104
        $this->inMemory->clear();
105
106
        return $this->pool->clear();
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function save(CacheItemInterface $item)
113
    {
114
        return $this->pool->save($item);
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function saveDeferred(CacheItemInterface $item)
121
    {
122
        return $this->pool->saveDeferred($item);
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function commit()
129
    {
130
        return $this->pool->commit();
131
    }
132
}
133