1
|
|
|
<?php |
2
|
|
|
/* zCache |
3
|
|
|
* |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Affero General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Affero General Public License |
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract Cache Class |
20
|
|
|
*/ |
21
|
|
|
class MemcachedCache extends AbstractCache |
22
|
|
|
{ |
23
|
|
|
private $mc; |
24
|
|
|
|
25
|
|
|
function __construct() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
global $memcacheServer, $memcachePort; |
28
|
|
|
|
29
|
|
|
$this->mc = new Memcached("zKB"); |
30
|
|
|
if(substr($memcacheServer, 0, 7) == "unix://") |
31
|
|
|
$this->mc->addServer(substr($memcacheServer, 7), 0); |
32
|
|
|
else |
33
|
|
|
$this->mc->addServer($memcacheServer, $memcachePort); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function get($key) |
37
|
|
|
{ |
38
|
|
|
return $this->mc->get($key); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $timeout |
43
|
|
|
*/ |
44
|
|
|
public function set($key, $value, $timeout) |
45
|
|
|
{ |
46
|
|
|
return $this->mc->set($key, $value, $timeout); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $timeout |
51
|
|
|
*/ |
52
|
|
|
public function replace($key, $value, $timeout) |
53
|
|
|
{ |
54
|
|
|
return $this->mc->replace($key, $value, $timeout); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $key |
59
|
|
|
*/ |
60
|
|
|
public function delete($key) |
61
|
|
|
{ |
62
|
|
|
return $this->mc->delete($key); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function increment($key, $step = 1, $timeout = 0) |
66
|
|
|
{ |
67
|
|
|
return $this->mc->increment($key, $step); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function decrement($key, $step = 1, $timeout = 0) |
71
|
|
|
{ |
72
|
|
|
return $this->mc->decrement($key, -$step); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function flush() |
76
|
|
|
{ |
77
|
|
|
return $this->mc->flush(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.