/
CacheManager.php
66 lines (58 loc) · 1.51 KB
/
CacheManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class Bbx_CacheManager {
public static function clean($request, $method) {
switch($method) {
case 'put':
self::_cleanForPut($request);
break;
case 'post':
case 'delete':
self::_cleanForPost($request);
break;
}
}
private static function _cache() {
$cache = Zend_Controller_Front::getInstance()
->getParam('bootstrap')
->getResource('cachemanager')
->getCache('page');
return $cache;
}
private static function _clean($tags) {
$san_tags = array();
foreach($tags as $k => $v) {
$san_tags[$k] = preg_replace('/[^A-Za-z0-9_]/', '', $v);
}
Bbx_Log::write('Cleaning tags ' . print_r($san_tags, true));
self::_cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $san_tags);
}
private static function _cleanForPut($request) {
$tags = array();
if (($rel = $request->getParam('rel'))) {
$tag = $request->getControllerName() . '_' . $request->getParam('id');
$tags[] = $tag;
$tags[] = $tag . '_' . $rel;
}
else {
$tags[] = $request->getControllerName();
if (($id = $request->getParam('id'))) {
$tags[] = $tags[0] . '_' . $id;
}
}
self::_clean($tags);
}
private static function _cleanForPost($request) {
$tags = array();
if (($rel = $request->getParam('rel'))) {
$tags[] = $rel;
$controller = $request->getControllerName();
$tags[] = $controller . '_' . $rel;
$tags[] = $controller . '_' . $request->getParam('id') . '_' . $rel;
}
else {
$tags[] = $request->getControllerName();
}
self::_clean($tags);
}
}
?>