WinCacheCache::doGetStats()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doctrine\Common\Cache;
4
5
use function count;
6
use function is_array;
7
use function wincache_ucache_clear;
8
use function wincache_ucache_delete;
9
use function wincache_ucache_exists;
10
use function wincache_ucache_get;
11
use function wincache_ucache_info;
12
use function wincache_ucache_meminfo;
13
use function wincache_ucache_set;
14
15
/**
16
 * WinCache cache provider.
17
 *
18
 * @link   www.doctrine-project.org
19
 */
20
class WinCacheCache extends CacheProvider
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function doFetch($id)
26
    {
27
        return wincache_ucache_get($id);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function doContains($id)
34
    {
35
        return wincache_ucache_exists($id);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function doSave($id, $data, $lifeTime = 0)
42
    {
43
        return wincache_ucache_set($id, $data, $lifeTime);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    protected function doDelete($id)
50
    {
51
        return wincache_ucache_delete($id);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function doFlush()
58
    {
59
        return wincache_ucache_clear();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    protected function doFetchMultiple(array $keys)
66
    {
67
        return wincache_ucache_get($keys);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
74
    {
75
        $result = wincache_ucache_set($keysAndValues, null, $lifetime);
76
77
        return empty($result);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    protected function doDeleteMultiple(array $keys)
84
    {
85
        $result = wincache_ucache_delete($keys);
86
87
        return is_array($result) && count($result) !== count($keys);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    protected function doGetStats()
94
    {
95
        $info    = wincache_ucache_info();
96
        $meminfo = wincache_ucache_meminfo();
97
98
        return [
99
            Cache::STATS_HITS             => $info['total_hit_count'],
100
            Cache::STATS_MISSES           => $info['total_miss_count'],
101
            Cache::STATS_UPTIME           => $info['total_cache_uptime'],
102
            Cache::STATS_MEMORY_USAGE     => $meminfo['memory_total'],
103
            Cache::STATS_MEMORY_AVAILABLE => $meminfo['memory_free'],
104
        ];
105
    }
106
}
107