|
@@ -12,7 +12,7 @@ however, this class has page caching functions superior to those of
|
12
|
12
|
memcache.
|
13
|
13
|
|
14
|
14
|
Also, Memcache::get and Memcache::set have been wrapped by
|
15
|
|
-CACHE::get_value and CACHE::cache_value. get_value uses the same argument
|
|
15
|
+Cache::get_value and Cache::cache_value. get_value uses the same argument
|
16
|
16
|
as get, but cache_value only takes the key, the value, and the duration
|
17
|
17
|
(no zlib).
|
18
|
18
|
|
|
@@ -24,14 +24,18 @@ memcached -d -m 8192 -l 10.10.0.1 -t8 -C
|
24
|
24
|
|
25
|
25
|
|*************************************************************************/
|
26
|
26
|
|
27
|
|
-if (!extension_loaded('memcache')) {
|
|
27
|
+if (!extension_loaded('memcache') && !extension_loaded('memcached')) {
|
28
|
28
|
die('Memcache Extension not loaded.');
|
29
|
29
|
}
|
30
|
30
|
|
31
|
|
-class CACHE extends Memcache {
|
32
|
|
- /**
|
33
|
|
- * Torrent Group cache version
|
34
|
|
- */
|
|
31
|
+if (class_exists('Memcached')) {
|
|
32
|
+ class MemcacheCompat extends Memcached {}
|
|
33
|
+} else {
|
|
34
|
+ class MemcacheCompat extends Memcache {}
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+class Cache extends MemcacheCompat {
|
|
38
|
+ // Torrent Group cache version
|
35
|
39
|
const GROUP_VERSION = 5;
|
36
|
40
|
|
37
|
41
|
public $CacheHits = [];
|
|
@@ -57,9 +61,14 @@ class CACHE extends Memcache {
|
57
|
61
|
public $InternalCache = true;
|
58
|
62
|
|
59
|
63
|
function __construct($Servers) {
|
|
64
|
+ if (is_subclass_of($this, 'Memcached')) parent::__construct();
|
60
|
65
|
$this->Servers = $Servers;
|
61
|
66
|
foreach ($Servers as $Server) {
|
62
|
|
- $this->addServer($Server['host'], $Server['port'], true, $Server['buckets']);
|
|
67
|
+ if (is_subclass_of($this, 'Memcache')) {
|
|
68
|
+ $this->addServer($Server['host'], $Server['port'], true, $Server['buckets']);
|
|
69
|
+ } else {
|
|
70
|
+ $this->addServer(str_replace('unix://', '', $Server['host']), $Server['port'], $Server['buckets']);
|
|
71
|
+ }
|
63
|
72
|
}
|
64
|
73
|
}
|
65
|
74
|
|
|
@@ -79,7 +88,9 @@ class CACHE extends Memcache {
|
79
|
88
|
if (empty($Key)) {
|
80
|
89
|
trigger_error("Cache insert failed for empty key");
|
81
|
90
|
}
|
82
|
|
- if (!$this->set($Key, $Value, 0, $Duration)) {
|
|
91
|
+ $SetParams = [$Key, $Value, 0, $Duration];
|
|
92
|
+ if (is_subclass_of($this, 'Memcached')) unset($SetParams[2]);
|
|
93
|
+ if (!$this->set(...$SetParams)) {
|
83
|
94
|
trigger_error("Cache insert failed for key $Key");
|
84
|
95
|
}
|
85
|
96
|
if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
|
|
@@ -98,7 +109,9 @@ class CACHE extends Memcache {
|
98
|
109
|
|
99
|
110
|
public function replace_value($Key, $Value, $Duration = 2592000) {
|
100
|
111
|
$StartTime = microtime(true);
|
101
|
|
- $this->replace($Key, $Value, false, $Duration);
|
|
112
|
+ $ReplaceParams = [$Key, $Value, false, $Duration];
|
|
113
|
+ if (is_subclass_of($this, 'Memcached')) unset($ReplaceParams[2]);
|
|
114
|
+ $this->replace(...$ReplaceParams);
|
102
|
115
|
if ($this->InternalCache && array_key_exists($Key, $this->CacheHits)) {
|
103
|
116
|
$this->CacheHits[$Key] = $Value;
|
104
|
117
|
}
|