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

midcom_services_cache_module   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 36
ccs 4
cts 7
cp 0.5714
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invalidate_all() 0 3 1
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