Completed
Branch master (89d155)
by Dan
14:32 queued 12:04
created

MemcacheStorage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 69
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addServer() 0 4 1
A has() 0 6 2
A flush() 0 4 1
A set() 0 4 1
A get() 0 4 1
A delete() 0 4 1
1
<?php
2
3
namespace Rs\Cache;
4
5
/**
6
 * Class MemcacheStorage
7
 * @package Rs\Cache
8
 */
9
class MemcacheStorage implements CacheStorageInterface
10
{
11
    private $mmc;
12
13
    public function __construct(\Memcached $memcache, $server = 'localhost', $port = 11211)
14
    {
15
        $this->mmc = $memcache;
16
        $this->mmc->addServer($server, $port);
17
    }
18
19
    /**
20
     * Add new server to Memcache pool.
21
     * @param $server
22
     * @param $port
23
     */
24
    public function addServer($server, $port)
25
    {
26
        $this->mmc->addServer($server, $port);
27
    }
28
29
    /**
30
     * @param string $key
31
     * @return bool
32
     */
33
    public function has($key){
34
        if (!empty($this->mmc->get($key))){
35
            return true;
36
        }
37
        return false;
38
    }
39
40
    /**
41
     * @param int $delay
42
     */
43
    public function flush($delay = 0)
44
    {
45
        $this->mmc->flush($delay);
46
    }
47
48
    /**
49
     * @param string $key
50
     * @param mixed $value
51
     * @param int $expires
52
     * @return void
53
     */
54
    public function set($key, $value, $expires)
55
    {
56
        $this->mmc->set($key, $value, $expires);
57
    }
58
59
    /**
60
     * @param string $key
61
     * @return mixed
62
     */
63
    public function get($key)
64
    {
65
        return $this->mmc->get($key);
66
    }
67
68
    /**
69
     * @param string $key
70
     * @return void
71
     */
72
    public function delete($key)
73
    {
74
        $this->mmc->delete($key);
75
    }
76
77
}
78