Completed
Push — master ( 89d155...6a85db )
by Dan
13:52 queued 06:12
created

MemcacheStorage::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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