Memcache::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpConsole\Storage;
4
5
/**
6
 * Memcache storage for postponed response data.
7
 *
8
 * @package PhpConsole
9
 * @version 3.1
10
 * @link http://consle.com
11
 * @author Sergey Barbushin http://linkedin.com/in/barbushin
12
 * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
13
 * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
14
 * @codeCoverageIgnore
15
 */
16
class Memcache extends ExpiringKeyValue {
17
18
	/** @var  \Memcache */
19
	protected $memcache;
20
21
	public function __construct($host = 'localhost', $port = 11211) {
22
		$this->memcache = new \Memcache();
23
		if(!$this->memcache->connect($host, $port)) {
24
			throw new \Exception('Unable to connect to Memcache server');
25
		}
26
	}
27
28
	/**
29
	 * Save data by auto-expire key
30
	 * @param $key
31
	 * @param string $data
32
	 * @param int $expire
33
	 */
34
	protected function set($key, $data, $expire) {
35
		$this->memcache->set($key, $data, null, $expire);
36
	}
37
38
	/**
39
	 * Get data by key if not expired
40
	 * @param $key
41
	 * @return string
42
	 */
43
	protected function get($key) {
44
		return $this->memcache->get($key);
45
	}
46
47
	/**
48
	 * Remove key in store
49
	 * @param $key
50
	 * @return mixed
51
	 */
52
	protected function delete($key) {
53
		$this->memcache->delete($key);
54
	}
55
}
56