Test Failed
Pull Request — 2.2 (#19980)
by
unknown
05:15
created

ArrayCache::init()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @link https://www.yiiframework.com/
5
 * @copyright Copyright (c) 2008 Yii Software LLC
6
 * @license https://www.yiiframework.com/license/
7
 */
8
9
namespace yii\caching;
10
11
/**
12
 * ArrayCache provides caching for the current request only by storing the values in an array.
13
 *
14
 * See [[Cache]] for common cache operations that ArrayCache supports.
15
 *
16
 * Unlike the [[Cache]], ArrayCache allows the expire parameter of [[set]], [[add]], [[multiSet]] and [[multiAdd]] to
17
 * be a floating point number, so you may specify the time in milliseconds (e.g. 0.1 will be 100 milliseconds).
18
 *
19
 * For enhanced performance of ArrayCache, you can disable serialization of the stored data by setting [[$serializer]] to `false`.
20
 *
21
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
22
 *
23
 * @author Carsten Brandt <[email protected]>
24
 * @since 2.0
25
 */
26
class ArrayCache extends Cache
27
{
28
    /**
29
     * @var \Yiisoft\Cache\ArrayCache $_cache 
30
     */
31
    private $_cache;
32
33 1
    function init()
34
    {
35 1
        $this->_cache = new \Yiisoft\Cache\ArrayCache();
36 1
    }
37
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 42
    public function exists($key)
43
    {
44 42
        return $this->_cache->get($key, null) != null;
45 33
    }
46
47
    /**
48 36
     * {@inheritdoc}
49
     */
50
    protected function getValue($key)
51
    {
52
        return $this->_cache->get($key, false);
53
    }
54 40
55
    /**
56 40
     * {@inheritdoc}
57 40
     */
58
    protected function setValue($key, $value, $duration)
59
    {
60
        return $this->_cache->set($key, $value, $duration);
61
    }
62
63 3
    /**
64
     * {@inheritdoc}
65 3
     */
66 2
    protected function addValue($key, $value, $duration)
67
    {
68 3
        if ($this->_cache->get($key, null) != null) {
69 3
            return false;
70
        }
71
72
        $this->_cache->set($key, $value, $duration);
73
        return true;
74
    }
75 1
76
    /**
77 1
     * {@inheritdoc}
78 1
     */
79
    protected function deleteValue($key)
80
    {
81
        return $this->_cache->delete($key);
82
    }
83
84 11
    /**
85
     * {@inheritdoc}
86 11
     */
87 11
    protected function flushValues()
88
    {
89
        return $this->_cache->clear();
90
    }
91
}
92