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 Apcu extends CacheApi implements CacheApiInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
public function isSupported($test = false) |
33
|
|
|
{ |
34
|
|
|
$supported = function_exists('apcu_fetch') && function_exists('apcu_store'); |
35
|
|
|
|
36
|
|
|
if ($test) |
37
|
|
|
return $supported; |
38
|
|
|
|
39
|
|
|
return parent::isSupported() && $supported; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritDoc} |
44
|
|
|
*/ |
45
|
|
|
public function connect() |
46
|
|
|
{ |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
|
|
public function getData($key, $ttl = null) |
54
|
|
|
{ |
55
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
56
|
|
|
|
57
|
|
|
$value = apcu_fetch($key . 'smf'); |
58
|
|
|
|
59
|
|
|
return !empty($value) ? $value : null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
|
|
public function putData($key, $value, $ttl = null) |
66
|
|
|
{ |
67
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
68
|
|
|
|
69
|
|
|
// An extended key is needed to counteract a bug in APC. |
70
|
|
|
if ($value === null) |
71
|
|
|
return apcu_delete($key . 'smf'); |
72
|
|
|
|
73
|
|
|
else |
74
|
|
|
return apcu_store($key . 'smf', $value, $ttl !== null ? $ttl : $this->ttl); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
|
|
public function cleanCache($type = '') |
81
|
|
|
{ |
82
|
|
|
$this->invalidateCache(); |
83
|
|
|
|
84
|
|
|
return apcu_clear_cache(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritDoc} |
89
|
|
|
*/ |
90
|
|
|
public function getVersion() |
91
|
|
|
{ |
92
|
|
|
return phpversion('apcu'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
?> |