Completed
Push — master ( 89223c...9f8254 )
by Andreas
51:18 queued 05:30
created

midcom_services_cache_module::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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 Doctrine\Common\Cache\CacheProvider;
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
     * Cache backend instance.
26
     *
27
     * @var Doctrine\Common\Cache\CacheProvider
28
     */
29
    protected $backend;
30
31
    /**
32
     * Initialize the module. This will initialize the class configuration
33
     * and call the corresponding event handler.
34
     */
35 1
    public function __construct(CacheProvider $backend)
36
    {
37 1
        $this->backend = $backend;
38 1
        $this->backend->setNamespace(get_class($this) . $_SERVER['SERVER_NAME']);
39 1
    }
40
41
    /**
42
     * Invalidate the cache completely, dropping all entries. The default implementation will
43
     * drop all entries from the cache backend using CacheProvider::flushAll().
44
     * Override this function if this behavior doesn't suit your needs.
45
     */
46
    public function invalidate_all()
47
    {
48
        $this->backend->flushAll();
49
    }
50
51
    /**
52
     * Invalidate all cache objects related to the given GUID.
53
     *
54
     * @param string $guid The GUID that has to be invalidated.
55
     * @param object $object The object that has to be invalidated (if available).
56
     */
57
    abstract public function invalidate($guid, $object = null);
58
}
59