1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Simple Machines Forum (SMF) |
5
|
|
|
* |
6
|
|
|
* @package SMF |
7
|
|
|
* @author Simple Machines https://www.simplemachines.org |
8
|
|
|
* @copyright 2020 Simple Machines and individual contributors |
9
|
|
|
* @license https://www.simplemachines.org/about/smf/license.php BSD |
10
|
|
|
* |
11
|
|
|
* @version 2.1 RC3 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace SMF\Cache\APIs; |
15
|
|
|
|
16
|
|
|
use SMF\Cache\CacheApi; |
17
|
|
|
use SMF\Cache\CacheApiInterface; |
18
|
|
|
|
19
|
|
|
if (!defined('SMF')) |
20
|
|
|
die('No direct access...'); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Our Cache API class |
24
|
|
|
* |
25
|
|
|
* @package CacheAPI |
26
|
|
|
*/ |
27
|
|
|
class Zend extends CacheApi implements CacheApiInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
public function isSupported($test = false) |
33
|
|
|
{ |
34
|
|
|
$supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get'); |
35
|
|
|
|
36
|
|
|
if ($test) |
37
|
|
|
return $supported; |
38
|
|
|
|
39
|
|
|
return parent::isSupported() && $supported; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function connect() |
43
|
|
|
{ |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function getData($key, $ttl = null) |
51
|
|
|
{ |
52
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
53
|
|
|
|
54
|
|
|
// Zend's pricey stuff. |
55
|
|
|
if (function_exists('zend_shm_cache_fetch')) |
56
|
|
|
return zend_shm_cache_fetch('SMF::' . $key); |
57
|
|
|
|
58
|
|
|
elseif (function_exists('output_cache_get')) |
59
|
|
|
return output_cache_get($key, $ttl); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
|
|
public function putData($key, $value, $ttl = null) |
66
|
|
|
{ |
67
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
68
|
|
|
|
69
|
|
|
if (function_exists('zend_shm_cache_store')) |
70
|
|
|
return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
71
|
|
|
|
72
|
|
|
elseif (function_exists('output_cache_put')) |
73
|
|
|
return output_cache_put($key, $value); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritDoc} |
78
|
|
|
*/ |
79
|
|
|
public function cleanCache($type = '') |
80
|
|
|
{ |
81
|
|
|
$this->invalidateCache(); |
82
|
|
|
|
83
|
|
|
return zend_shm_cache_clear('SMF'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritDoc} |
88
|
|
|
*/ |
89
|
|
|
public function getVersion() |
90
|
|
|
{ |
91
|
|
|
return zend_version(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
?> |