Completed
Push — master ( 579af5...b29473 )
by Oleg
07:53
created

ArrayCache::increment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php /** MicroArrayCache */
2
3
namespace Micro\Cache;
4
5
use Micro\File\Type;
6
7
/**
8
 * Class ArrayCache
9
 *
10
 * @author Oleg Lunegov <[email protected]>
11
 * @link https://github.com/lugnsk/micro
12
 * @copyright Copyright &copy; 2013 Oleg Lunegov
13
 * @license /LICENSE
14
 * @package Micro
15
 * @subpackage Cache
16
 * @version 1.0
17
 * @since 1.0
18
 */
19
class ArrayCache extends BaseCache
20
{
21
    /** @var array $driver array as driver */
22
    protected $driver = [];
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function check()
28
    {
29
        return true;
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function get($name)
36
    {
37
        return !empty($this->driver[$name]) ? $this->driver[$name] : false;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function set($name, $value)
44
    {
45
        $this->driver[$name] = $value;
46
    }
47
48
    /**
49
     * 2@inheritdoc
50
     */
51
    public function delete($name)
52
    {
53
        if (!empty($this->driver[$name])) {
54
            unset($this->driver[$name]);
55
        }
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function clean()
62
    {
63
        $this->driver = [];
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function info()
70
    {
71
        return count($this->driver);
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function getMeta($id)
78
    {
79
        if (!empty($this->driver[$id])) {
80
            return Type::getType($this->driver[$id]);
81
        }
82
83
        return false;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function increment($name, $offset = 1)
90
    {
91
        $this->driver[$name] += $offset;
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97
    public function decrement($name, $offset = 1)
98
    {
99
        $this->driver[$name] -= $offset;
100
    }
101
}
102