|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
ar_pinp::allow('ar_cache_memcachedStore'); |
|
4
|
|
|
|
|
5
|
|
|
class ar_cache_memcachedStore implements ar_cacheStoreInterface, arKeyValueStoreInterface { |
|
6
|
|
|
private $timeout = 7200; |
|
7
|
|
|
private $mc = null; |
|
8
|
|
|
public function __construct( $servers, $timeout = 7200, $prefix = 'AR_') { |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
if ( is_string($timeout) ) { |
|
11
|
|
|
$timeout = strtotime( $timeout, 0); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
$this->timeout = $timeout; |
|
15
|
|
|
$this->mc = $mc = new memCached(); |
|
16
|
|
|
$mc->addServers($servers); |
|
17
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
// key |
|
21
|
|
|
public function get( $path ) { |
|
22
|
|
|
$res = $this->mc->get($path);; |
|
23
|
|
|
$code = $this->mc->getResultCode(); |
|
24
|
|
|
if($code !== MEMCACHED_SUCCESS ){ |
|
25
|
|
|
return $res; |
|
26
|
|
|
} |
|
27
|
|
|
return null; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getIfFresh( $path, $timeout = 0 ) { |
|
31
|
|
|
// we do not know if it is fresh |
|
32
|
|
|
return $this->get( $path ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// key value expire |
|
36
|
|
|
public function set( $path, $value, $timeout = 7200 ) { |
|
37
|
|
|
$res = $this->mc->set($path, $value, $timeout); |
|
38
|
|
|
return $res; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// meta info |
|
42
|
|
|
public function info( $path ) { |
|
43
|
|
|
$res = []; |
|
44
|
|
|
// FIXME: implement this |
|
45
|
|
|
return $res; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// remove key |
|
49
|
|
|
public function clear( $path = null ) { |
|
50
|
|
|
return $this->mc->delete($path); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function subStore( $path ) { |
|
54
|
|
|
// geen idee eigenlijk |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// hoeveel tijd hebben we nog |
|
58
|
|
|
public function isFresh( $path ) { |
|
59
|
|
|
$res = $this->get( $path ); |
|
60
|
|
|
return ($res !== null); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function putvar( $name, $value ) { |
|
64
|
|
|
return $this->set( $name, $value ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getvar( $name ) { |
|
68
|
|
|
return $this->get( $name ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// purge, we do not have the option to partial purge, so purge all |
|
72
|
|
|
public function purge($name=null){ |
|
73
|
|
|
return $this->mc->flush(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.