Completed
Push — master ( e02af6...f80686 )
by Nazar
05:32
created

Memcached::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A Memcached::set_internal() 0 3 1
1
<?php
2
/**
3
 * @package   CleverStyle CMS
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs\Cache;
9
use
10
	cs\Core;
11
12
/**
13
 * Provides cache functionality based on Memcached.
14
 * Support optionally base configuration option Core::instance()->memcached_host and Core::instance()->memcached_port
15
 */
16
class Memcached extends _Abstract_with_namespace {
17
	/**
18
	 * @var \Memcached
19
	 */
20
	protected $memcached;
21
	function __construct () {
22
		if (!extension_loaded('memcached')) {
23
			return;
24
		}
25
		$this->memcached = new \Memcached(DOMAIN);
26
		$Core            = Core::instance();
27
		$this->memcached->addServer($Core->memcached_host ?: '127.0.0.1', $Core->memcached_port ?: 11211);
28
	}
29
	/**
30
	 * @inheritdoc
31
	 */
32
	protected function available_internal () {
33
		return (bool)$this->memcached;
34
	}
35
	/**
36
	 * @inheritdoc
37
	 */
38
	protected function get_internal ($item) {
39
		return $this->memcached->get($item);
40
	}
41
	/**
42
	 * @inheritdoc
43
	 */
44
	protected function set_internal ($item, $data) {
45
		return $this->memcached->set($item, $data);
46
	}
47
	/**
48
	 * @inheritdoc
49
	 */
50
	protected function del_internal ($item) {
51
		return $this->memcached->delete($item);
52
	}
53
	/**
54
	 * @inheritdoc
55
	 */
56
	protected function increment_internal ($item) {
57
		return $this->memcached->increment($item);
58
	}
59
	/**
60
	 * @inheritdoc
61
	 */
62
	protected function clean_internal () {
63
		return $this->memcached->flush();
64
	}
65
	/**
66
	 * Close connections to memcached servers
67
	 */
68
	function __destruct () {
69
		if ($this->memcached) {
70
			$this->memcached->quit();
71
		}
72
	}
73
}
74