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

apc_cache   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 65
rs 10
wmc 14

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersion() 0 3 1
A putData() 0 9 3
A cleanCache() 0 14 4
A getData() 0 7 2
A isSupported() 0 7 4
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 apc_cache extends cache_api
23
{
24
	/**
25
	 * {@inheritDoc}
26
	 */
27
	public function isSupported($test = false)
28
	{
29
		$supported = function_exists('apc_fetch') && function_exists('apc_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 = apc_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 apc_delete($key . 'smf');
58
		else
59
			return apc_store($key . 'smf', $value, $ttl !== null ? $ttl : $this->ttl);
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	public function cleanCache($type = '')
66
	{
67
		// if passed a type, clear that type out
68
		if ($type === '' || $type === 'data')
69
		{
70
			// Always returns true.
71
			apc_clear_cache('user');
72
			apc_clear_cache('system');
73
		}
74
		elseif ($type === 'user')
75
			apc_clear_cache('user');
76
77
		$this->invalidateCache();
78
		return true;
79
	}
80
81
	/**
82
	 * {@inheritDoc}
83
	 */
84
	public function getVersion()
85
	{
86
		return phpversion('apc');
87
	}
88
}
89
90
?>