|
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
|
|
|
|