Completed
Pull Request — master (#22)
by
unknown
03:38
created

Memcached::setComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace League\Flysystem\Cached\Storage;
4
5
use Memcached as NativeMemcached;
6
7
class Memcached extends AbstractCache
8
{
9
    /**
10
     * @var string storage key
11
     */
12
    protected $key;
13
14
    /**
15
     * @var int|null seconds until cache expiration
16
     */
17
    protected $expire;
18
19
    /**
20
     * @var \Memcached Memcached instance
21
     */
22
    protected $memcached;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param \Memcached $memcached
28
     * @param string     $key       storage key
29
     * @param int|null   $expire    seconds until cache expiration
30
     */
31 12
    public function __construct(NativeMemcached $memcached, $key = 'flysystem', $expire = null)
32
    {
33 12
        $this->key = $key;
34 12
        $this->expire = $expire;
35 12
        $this->memcached = $memcached;
36 12
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 6
    public function load()
42
    {
43 6
        $contents = $this->memcached->get($this->key);
44
45 6
        if ($contents !== false) {
46 3
            $this->setFromStorage($contents);
47 3
        }
48 6
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 3
    public function save()
54
    {
55 3
        $contents = $this->getForStorage();
56 3
        $expiration = $this->expire === null ? 0 : time() + $this->expire;
57 3
        $this->memcached->set($this->key, $contents, $expiration);
58 3
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 6
    public function isComplete($dirname, $recursive) {
64 6
        return FALSE;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 3
    public function setComplete($dirname, $recursive) {
71
        // The memcache adapter can never be complete due to cache evictions.
72 3
    }
73
}
74