|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Simple Machines Forum (SMF) |
|
5
|
|
|
* |
|
6
|
|
|
* @package SMF |
|
7
|
|
|
* @author Simple Machines http://www.simplemachines.org |
|
8
|
|
|
* @copyright 2017 Simple Machines and individual contributors |
|
9
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
|
10
|
|
|
* |
|
11
|
|
|
* @version 2.1 Beta 4 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
if (!defined('SMF')) |
|
15
|
|
|
die('Hacking attempt...'); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Our Cache API class |
|
19
|
|
|
* @package cacheAPI |
|
20
|
|
|
*/ |
|
21
|
|
|
class apc_cache extends cache_api |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function isSupported($test = false) |
|
27
|
|
|
{ |
|
28
|
|
|
$supported = function_exists('apc_fetch') && function_exists('apc_store'); |
|
29
|
|
|
|
|
30
|
|
|
if ($test) |
|
31
|
|
|
return $supported; |
|
32
|
|
|
return parent::isSupported() && $supported; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritDoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getData($key, $ttl = null) |
|
39
|
|
|
{ |
|
40
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
|
41
|
|
|
|
|
42
|
|
|
return apc_fetch($key . 'smf'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
public function putData($key, $value, $ttl = null) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$key = $this->prefix . strtr($key, ':/', '-_'); |
|
51
|
|
|
|
|
52
|
|
|
// An extended key is needed to counteract a bug in APC. |
|
53
|
|
|
if ($value === null) |
|
54
|
|
|
return apc_delete($key . 'smf'); |
|
55
|
|
|
else |
|
56
|
|
|
return apc_store($key . 'smf', $value, $ttl); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritDoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function cleanCache($type = '') |
|
63
|
|
|
{ |
|
64
|
|
|
// if passed a type, clear that type out |
|
65
|
|
|
if ($type === '' || $type === 'data') |
|
66
|
|
|
{ |
|
67
|
|
|
// Always returns true. |
|
68
|
|
|
apc_clear_cache('user'); |
|
69
|
|
|
apc_clear_cache('system'); |
|
70
|
|
|
} |
|
71
|
|
|
elseif ($type === 'user') |
|
72
|
|
|
apc_clear_cache('user'); |
|
73
|
|
|
|
|
74
|
|
|
$this->invalidateCache(); |
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritDoc} |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getVersion() |
|
82
|
|
|
{ |
|
83
|
|
|
return phpversion('apc'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
?> |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.