Completed
Push — master ( d87efb...5aade8 )
by Auke
22s
created

ar_cache_memcachedStore::purge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 5 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "implement this"
Loading history...
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