Passed
Pull Request — release-2.1 (#6262)
by Jeremy
04:04
created

apcu_cache   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 0 7 4
A cleanCache() 0 4 1
A getVersion() 0 3 1
A putData() 0 9 3
A getData() 0 7 2
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
if (!defined('SMF'))
15
	die('Hacking attempt...');
16
17
/**
18
 * Our Cache API class
19
 *
20
 * @package cacheAPI
21
 */
22
class apcu_cache extends cache_api
23
{
24
	/**
25
	 * {@inheritDoc}
26
	 */
27
	public function isSupported($test = false)
28
	{
29
		$supported = function_exists('apcu_fetch') && function_exists('apcu_store');
30
31
		if ($test)
32
			return $supported;
33
		return parent::isSupported() && $supported;
34
	}
35
36
	/**
37
	 * {@inheritDoc}
38
	 */
39
	public function getData($key, $ttl = null)
40
	{
41
		$key = $this->prefix . strtr($key, ':/', '-_');
42
43
		$value = apcu_fetch($key . 'smf');
44
45
		return !empty($value) ? $value : null;
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	public function putData($key, $value, $ttl = null)
52
	{
53
		$key = $this->prefix . strtr($key, ':/', '-_');
54
55
		// An extended key is needed to counteract a bug in APC.
56
		if ($value === null)
57
			return apcu_delete($key . 'smf');
58
		else
59
			return apcu_store($key . 'smf', $value, $ttl !== null ? $ttl : $this->ttl);
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	public function cleanCache($type = '')
66
	{
67
		$this->invalidateCache();
68
		return apcu_clear_cache();
69
	}
70
71
	/**
72
	 * {@inheritDoc}
73
	 */
74
	public function getVersion()
75
	{
76
		return phpversion('apcu');
77
	}
78
}
79
80
?>