Completed
Push — master ( a1970e...6c5d6a )
by Oleg
04:15
created

WincacheDriver::decrement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php /** MicroWincacheDriver */
2
3
namespace Micro\Cache\Drivers;
4
5
use Micro\Base\Exception;
6
7
/**
8
 * Class WincacheDriver
9
 *
10
 * @author Oleg Lunegov <[email protected]>
11
 * @link https://github.com/linpax/microphp-framework
12
 * @copyright Copyright (c) 2013 Oleg Lunegov
13
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
14
 * @package Micro
15
 * @subpackage Cache\Driver
16
 * @version 1.0
17
 * @since 1.0
18
 */
19
class WincacheDriver extends CacheDriver
20
{
21
    /**
22
     * Constructor
23
     *
24
     * @access public
25
     *
26
     * @param array $config array config
27
     *
28
     * @result void
29
     * @throws Exception
30
     */
31
    public function __construct(array $config = [])
32
    {
33
        parent::__construct($config);
34
35
        if (!$this->check()) {
36
            throw new Exception('Extension WinCache not installed');
37
        }
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function check()
44
    {
45
        return (!extension_loaded('wincache')) ? true : false;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function get($name)
52
    {
53
        $success = false;
54
        $data = wincache_ucache_get($name, $success);
55
56
        return $success ? $data : false;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function set($name, $value, $duration = 0)
63
    {
64
        return wincache_ucache_set($name, $value, $duration);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function delete($name)
71
    {
72
        return wincache_ucache_delete($name);
73
    }
74
75
    /**
76
     * Clean all data from cache
77
     *
78
     * @access public
79
     * @return mixed
80
     */
81
    public function clean()
82
    {
83
        return wincache_ucache_clear();
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function info()
90
    {
91
        return wincache_ucache_info(true);
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97
    public function getMeta($id)
98
    {
99
        if ($stored = wincache_ucache_info(false, $id)) {
100
            $age = $stored['ucache_entries'][1]['age_seconds'];
101
            $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
102
            $hitCount = $stored['ucache_entries'][1]['hitcount'];
103
104
            return ['expire' => $ttl - $age, 'hitcount' => $hitCount, 'age' => $age, 'ttl' => $ttl];
105
        }
106
107
        return false;
108
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113 View Code Duplication
    public function increment($name, $offset = 1)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $success = false;
116
        $value = wincache_ucache_inc($name, $offset, $success);
117
118
        return ($success === true) ? $value : false;
119
    }
120
121
    /**
122
     * @inheritdoc
123
     */
124 View Code Duplication
    public function decrement($name, $offset = 1)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        $success = false;
127
        $value = wincache_ucache_dec($name, $offset, $success);
128
129
        return ($success === true) ? $value : false;
130
    }
131
} 
132