Issues (36)

lib/Doctrine/Common/Cache/ApcuCache.php (1 issue)

1
<?php
2
3
namespace Doctrine\Common\Cache;
4
5
use function apcu_cache_info;
6
use function apcu_clear_cache;
7
use function apcu_delete;
8
use function apcu_exists;
9
use function apcu_fetch;
10
use function apcu_sma_info;
11
use function apcu_store;
12
use function count;
13
14
/**
15
 * APCu cache provider.
16
 *
17
 * @link   www.doctrine-project.org
18
 */
19
class ApcuCache extends CacheProvider
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 75
    protected function doFetch($id)
25
    {
26 75
        return apcu_fetch($id);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 70
    protected function doContains($id)
33
    {
34 70
        return apcu_exists($id);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 73
    protected function doSave($id, $data, $lifeTime = 0)
41
    {
42 73
        return apcu_store($id, $data, $lifeTime);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 44
    protected function doDelete($id)
49
    {
50
        // apcu_delete returns false if the id does not exist
51 44
        return apcu_delete($id) || ! apcu_exists($id);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    protected function doDeleteMultiple(array $keys)
58
    {
59 1
        $result = apcu_delete($keys);
60
61 1
        return $result !== false && count($result) !== count($keys);
0 ignored issues
show
It seems like $result can also be of type true; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        return $result !== false && count(/** @scrutinizer ignore-type */ $result) !== count($keys);
Loading history...
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 2
    protected function doFlush()
68
    {
69 2
        return apcu_clear_cache();
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 2
    protected function doFetchMultiple(array $keys)
76
    {
77 2
        return apcu_fetch($keys) ?: [];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 1
    protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
84
    {
85 1
        $result = apcu_store($keysAndValues, null, $lifetime);
86
87 1
        return empty($result);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 1
    protected function doGetStats()
94
    {
95 1
        $info = apcu_cache_info(true);
96 1
        $sma  = apcu_sma_info();
97
98
        return [
99 1
            Cache::STATS_HITS             => $info['num_hits'],
100 1
            Cache::STATS_MISSES           => $info['num_misses'],
101 1
            Cache::STATS_UPTIME           => $info['start_time'],
102 1
            Cache::STATS_MEMORY_USAGE     => $info['mem_size'],
103 1
            Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
104
        ];
105
    }
106
}
107