Completed
Push — 8.x-1.x ( 36574f...05bb7c )
by
unknown
24:36
created

DrupalCache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Drupal\controller_annotations\Cache;
4
5
use Doctrine\Common\Cache\CacheProvider;
6
use Drupal\Core\Cache\CacheBackendInterface;
7
8
class DrupalCache extends CacheProvider
9
{
10
    /**
11
     * @var CacheBackendInterface
12
     */
13
    private $cache;
14
15
    /**
16
     * @param CacheBackendInterface $cache
17
     */
18 11
    public function __construct(CacheBackendInterface $cache)
19
    {
20 11
        $this->cache = $cache;
21 11
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 9
    protected function doFetch($id)
27
    {
28 9
        return $this->cache->get($id);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 1
    protected function doContains($id)
35
    {
36 1
        return $this->doFetch($id) !== false;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 6
    protected function doSave($id, $data, $lifeTime = 0)
43
    {
44 6
        if ($lifeTime === 0) {
45 6
            $this->cache->set($id, $data);
46
        }
47
        else {
48 1
            $this->cache->set($id, $data, time() + $lifeTime);
49
        }
50
51 6
        return true;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 1
    protected function doDelete($id)
58
    {
59 1
        $this->cache->delete($id);
60
61 1
        return true;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 1
    protected function doFlush()
68
    {
69 1
        $this->cache->deleteAll();
70
71 1
        return true;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 1
    protected function doGetStats()
78
    {
79 1
        return;
80
    }
81
}
82