CacheAnalyzerBackend::freeze()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * Analyse backend
4
 *
5
 * @package CacheCheck\Cache\Backend
6
 * @author  Julian Seitz
7
 */
8
9
namespace HDNET\CacheCheck\Cache\Backend;
10
11
use TYPO3\CMS\Core\Cache\Backend\FreezableBackendInterface;
12
use TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface;
13
use TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface;
14
15
/**
16
 * Class CacheAnalyzerBackend
17
 */
18
class CacheAnalyzerBackend extends AbstractAnalyzerBackend implements FreezableBackendInterface, PhpCapableBackendInterface, TaggableBackendInterface
19
{
20
21
    /**
22
     * Setter for compression flags bit
23
     *
24
     * @param boolean $useCompression
25
     *
26
     * @return void
27
     */
28
    protected function setCompression($useCompression)
0 ignored issues
show
Unused Code introduced by
The parameter $useCompression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
    }
31
32
    /**
33
     * Saves data in the cache.
34
     *
35
     * @param string  $entryIdentifier An identifier for this specific cache entry
36
     * @param string  $data            The data to be stored
37
     * @param array   $tags            Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
38
     * @param integer $lifetime        Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
39
     *
40
     * @return void
41
     * @throws \TYPO3\CMS\Core\Cache\Exception if no cache frontend has been set.
42
     * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException if the data is not a string
43
     */
44
    public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
45
    {
46
        $this->logEntry('set', $entryIdentifier, $data);
47
        $this->originalBackend->set($entryIdentifier, $data, $tags, $lifetime);
48
    }
49
50
    /**
51
     * Loads data from the cache.
52
     *
53
     * @param string $entryIdentifier An identifier which describes the cache entry to load
54
     *
55
     * @return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
56
     */
57
    public function get($entryIdentifier)
58
    {
59
        $this->logEntry('get', $entryIdentifier);
60
        $data = $this->originalBackend->get($entryIdentifier);
61
        $this->logEntry('getAfter', $entryIdentifier);
62
        if ($data !== false) {
63
            $this->logEntry('getTRUE', $entryIdentifier);
64
        }
65
        return $data;
66
    }
67
68
    /**
69
     * Checks if a cache entry with the specified identifier exists.
70
     *
71
     * @param string $entryIdentifier An identifier specifying the cache entry
72
     *
73
     * @return boolean TRUE if such an entry exists, FALSE if not
74
     */
75
    public function has($entryIdentifier)
76
    {
77
        $this->logEntry('has', $entryIdentifier);
78
        $data = $this->originalBackend->has($entryIdentifier);
79
        if ($data !== false) {
80
            $this->logEntry('hasTRUE', $entryIdentifier);
81
        }
82
        return $data;
83
    }
84
85
    /**
86
     * Removes all cache entries matching the specified identifier.
87
     * Usually this only affects one entry but if - for what reason ever -
88
     * old entries for the identifier still exist, they are removed as well.
89
     *
90
     * @param string $entryIdentifier Specifies the cache entry to remove
91
     *
92
     * @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found
93
     */
94
    public function remove($entryIdentifier)
95
    {
96
        $this->logEntry('remove', $entryIdentifier);
97
        return $this->originalBackend->remove($entryIdentifier);
98
    }
99
100
    /**
101
     * Removes all cache entries of this cache.
102
     *
103
     * @return void
104
     */
105
    public function flush()
106
    {
107
        $this->logEntry('flush');
108
        $this->originalBackend->flush();
109
    }
110
111
    /**
112
     * Does garbage collection
113
     *
114
     * @return void
115
     */
116
    public function collectGarbage()
117
    {
118
        $this->logEntry('collectGarbage');
119
        $this->originalBackend->collectGarbage();
120
    }
121
122
    /**
123
     * Freezes this cache backend.
124
     *
125
     * All data in a frozen backend remains unchanged and methods which try to add
126
     * or modify data result in an exception thrown. Possible expiry times of
127
     * individual cache entries are ignored.
128
     *
129
     * On the positive side, a frozen cache backend is much faster on read access.
130
     * A frozen backend can only be thawn by calling the flush() method.
131
     *
132
     * @return void
133
     */
134
    public function freeze()
135
    {
136
        if ($this->originalBackend instanceof FreezableBackendInterface) {
137
            $this->logEntry('freeze');
138
            $this->originalBackend->freeze();
139
        }
140
    }
141
142
    /**
143
     * Tells if this backend is frozen.
144
     *
145
     * @return boolean
146
     */
147
    public function isFrozen()
148
    {
149
        if ($this->originalBackend instanceof FreezableBackendInterface) {
150
            $this->logEntry('isFrozen');
151
            return $this->originalBackend->isFrozen();
152
        }
153
        return false;
154
    }
155
156
    /**
157
     * Loads PHP code from the cache and require_onces it right away.
158
     *
159
     * @param string $entryIdentifier An identifier which describes the cache entry to load
160
     *
161
     * @return mixed Potential return value from the include operation
162
     */
163
    public function requireOnce($entryIdentifier)
164
    {
165
        if ($this->originalBackend instanceof PhpCapableBackendInterface) {
166
            $this->logEntry('requireOnce', $entryIdentifier);
167
            $data = $this->originalBackend->requireOnce($entryIdentifier);
168
            if ($data !== false) {
169
                $this->logEntry('requireOnceTRUE', $entryIdentifier);
170
            }
171
            return $data;
172
        }
173
        return false;
174
    }
175
176
    /**
177
     * Removes all cache entries of this cache which are tagged by the specified tag.
178
     *
179
     * @param string $tag The tag the entries must have
180
     *
181
     * @return void
182
     */
183
    public function flushByTag($tag)
184
    {
185
        if ($this->originalBackend instanceof TaggableBackendInterface) {
186
            $this->logEntry('flushByTag');
187
            $this->originalBackend->flushByTag($tag);
188
        }
189
    }
190
191
    /**
192
     * Finds and returns all cache entry identifiers which are tagged by the
193
     * specified tag
194
     *
195
     * @param string $tag The tag to search for
196
     *
197
     * @return array An array with identifiers of all matching entries. An empty array if no entries matched
198
     */
199
    public function findIdentifiersByTag($tag)
200
    {
201
        if ($this->originalBackend instanceof TaggableBackendInterface) {
202
            $this->logEntry('findIdentifiersByTag');
203
            return $this->originalBackend->findIdentifiersByTag($tag);
204
        }
205
        return [];
206
    }
207
}
208