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 * Xcache cache driver.
24 *
25 * @link www.doctrine-project.org
26 * @since 2.0
27 * @author Benjamin Eberlei <kontakt@beberlei.de>
28 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
29 * @author Jonathan Wage <jonwage@gmail.com>
30 * @author Roman Borschel <roman@code-factory.org>
31 * @author David Abdemoulaie <dave@hobodave.com>
32 */
33 class XcacheCache extends CacheProvider
34 {
35 /**
36 * {@inheritdoc}
37 */
38 protected function doFetch($id)
39 {
40 return $this->doContains($id) ? unserialize(xcache_get($id)) : false;
41 }
42  
43 /**
44 * {@inheritdoc}
45 */
46 protected function doContains($id)
47 {
48 return xcache_isset($id);
49 }
50  
51 /**
52 * {@inheritdoc}
53 */
54 protected function doSave($id, $data, $lifeTime = 0)
55 {
56 return xcache_set($id, serialize($data), (int) $lifeTime);
57 }
58  
59 /**
60 * {@inheritdoc}
61 */
62 protected function doDelete($id)
63 {
64 return xcache_unset($id);
65 }
66  
67 /**
68 * {@inheritdoc}
69 */
70 protected function doFlush()
71 {
72 $this->checkAuthorization();
73  
74 xcache_clear_cache(XC_TYPE_VAR);
75  
76 return true;
77 }
78  
79 /**
80 * Checks that xcache.admin.enable_auth is Off.
81 *
82 * @return void
83 *
84 * @throws \BadMethodCallException When xcache.admin.enable_auth is On.
85 */
86 protected function checkAuthorization()
87 {
88 if (ini_get('xcache.admin.enable_auth')) {
89 throw new \BadMethodCallException(
90 'To use all features of \Doctrine\Common\Cache\XcacheCache, '
91 . 'you must set "xcache.admin.enable_auth" to "Off" in your php.ini.'
92 );
93 }
94 }
95  
96 /**
97 * {@inheritdoc}
98 */
99 protected function doGetStats()
100 {
101 $this->checkAuthorization();
102  
103 $info = xcache_info(XC_TYPE_VAR, 0);
104 return array(
105 Cache::STATS_HITS => $info['hits'],
106 Cache::STATS_MISSES => $info['misses'],
107 Cache::STATS_UPTIME => null,
108 Cache::STATS_MEMORY_USAGE => $info['size'],
109 Cache::STATS_MEMORY_AVAILABLE => $info['avail'],
110 );
111 }
112 }