scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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 doFlush()
68 {
69 return apcu_clear_cache();
70 }
71  
72 /**
73 * {@inheritdoc}
74 */
75 protected function doFetchMultiple(array $keys)
76 {
77 return apcu_fetch($keys) ?: [];
78 }
79  
80 /**
81 * {@inheritdoc}
82 */
83 protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
84 {
85 $result = apcu_store($keysAndValues, null, $lifetime);
86  
87 return empty($result);
88 }
89  
90 /**
91 * {@inheritdoc}
92 */
93 protected function doGetStats()
94 {
95 $info = apcu_cache_info(true);
96 $sma = apcu_sma_info();
97  
98 return array(
99 Cache::STATS_HITS => $info['num_hits'],
100 Cache::STATS_MISSES => $info['num_misses'],
101 Cache::STATS_UPTIME => $info['start_time'],
102 Cache::STATS_MEMORY_USAGE => $info['mem_size'],
103 Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
104 );
105 }
106 }