Security update to Drupal 8.4.6
[yaffs-website] / vendor / doctrine / cache / lib / Doctrine / Common / Cache / ApcuCache.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20 namespace Doctrine\Common\Cache;
21
22 /**
23  * APCu cache provider.
24  *
25  * @link   www.doctrine-project.org
26  * @since  1.6
27  * @author Kévin Dunglas <dunglas@gmail.com>
28  */
29 class ApcuCache extends CacheProvider
30 {
31     /**
32      * {@inheritdoc}
33      */
34     protected function doFetch($id)
35     {
36         return apcu_fetch($id);
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     protected function doContains($id)
43     {
44         return apcu_exists($id);
45     }
46
47     /**
48      * {@inheritdoc}
49      */
50     protected function doSave($id, $data, $lifeTime = 0)
51     {
52         return apcu_store($id, $data, $lifeTime);
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     protected function doDelete($id)
59     {
60         // apcu_delete returns false if the id does not exist
61         return apcu_delete($id) || ! apcu_exists($id);
62     }
63
64     /**
65      * {@inheritdoc}
66      */
67     protected function doDeleteMultiple(array $keys)
68     {
69         $result = apcu_delete($keys);
70
71         return false !== $result && count($result) !== count($keys);
72     }
73
74     /**
75      * {@inheritdoc}
76      */
77     protected function doFlush()
78     {
79         return apcu_clear_cache();
80     }
81
82     /**
83      * {@inheritdoc}
84      */
85     protected function doFetchMultiple(array $keys)
86     {
87         return apcu_fetch($keys) ?: [];
88     }
89
90     /**
91      * {@inheritdoc}
92      */
93     protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
94     {
95         $result = apcu_store($keysAndValues, null, $lifetime);
96
97         return empty($result);
98     }
99
100     /**
101      * {@inheritdoc}
102      */
103     protected function doGetStats()
104     {
105         $info = apcu_cache_info(true);
106         $sma  = apcu_sma_info();
107
108         return [
109             Cache::STATS_HITS             => $info['num_hits'],
110             Cache::STATS_MISSES           => $info['num_misses'],
111             Cache::STATS_UPTIME           => $info['start_time'],
112             Cache::STATS_MEMORY_USAGE     => $info['mem_size'],
113             Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
114         ];
115     }
116 }