Passed
Push — master ( 8a140a...6eed6d )
by Andreas
26:05
created

midcom_services_cache_module::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.services
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use Symfony\Component\Cache\Adapter\AdapterInterface;
10
11
/**
12
 * This is the base class for the MidCOM cache modules. It provides a basic infrastructure
13
 * for building your own caching service, providing hooks for initialization.
14
 *
15
 * It provides convenience methods to start up the cache module, for example for the creation
16
 * of a cache backend instance. There is no specific initialization done during startup, to
17
 * allow the modules to do their own magic during startup (it is difficult to generalize such
18
 * stuff).
19
 *
20
 * @package midcom.services
21
 */
22
abstract class midcom_services_cache_module
23
{
24
    /**
25
     * @var AdapterInterface
26
     */
27
    protected $backend;
28
29
    /**
30
     * Initialize the module. This will initialize the class configuration
31
     * and call the corresponding event handler.
32
     */
33 1
    public function __construct(AdapterInterface $backend)
34
    {
35 1
        $this->backend = $backend;
36 1
    }
37
38
    /**
39
     * Invalidate the cache completely, dropping all entries. The default implementation will
40
     * drop all entries from the cache backend using AdapterInterface::clear().
41
     * Override this function if this behavior doesn't suit your needs.
42
     */
43
    public function invalidate_all()
44
    {
45
        $this->backend->clear();
46
    }
47
48
    /**
49
     * Invalidate all cache objects related to the given GUID.
50
     */
51
    abstract public function invalidate(string $guid, $object = null);
52
}
53