ar_cache_memcachedStore   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A get() 0 8 2
A getIfFresh() 0 4 1
A set() 0 4 1
A info() 0 5 1
A clear() 0 3 1
A subStore() 0 3 1
A isFresh() 0 4 1
A putvar() 0 3 1
A getvar() 0 3 1
A purge() 0 3 1
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_') {
0 ignored issues
show
Unused Code introduced by
The parameter $prefix is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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