Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Apc.php 7490 2010-03-29 19:53:27Z jwage $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * APC Cache Driver
24
 *
25
 * @package     Doctrine
26
 * @subpackage  Cache
27
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28
 * @link        www.doctrine-project.org
29
 * @since       1.0
30
 * @version     $Revision: 7490 $
31
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
32
 * @author      Jonathan H. Wage <jonwage@gmail.com>
33
 */
34
class Doctrine_Cache_Apc extends Doctrine_Cache_Driver
35
{
36
    /**
37
     * constructor
38
     *
39
     * @param array $options    associative array of cache driver options
40
     */
41
    public function __construct($options = array())
42
    {
43
        if ( ! extension_loaded('apc')) {
44
            throw new Doctrine_Cache_Exception('The apc extension must be loaded for using this backend !');
45
        }
46
        parent::__construct($options);
47
    }
48
 
49
    /**
50
     * Fetch a cache record from this cache driver instance
51
     *
52
     * @param string $id cache id
53
     * @param boolean $testCacheValidity        if set to false, the cache validity won't be tested
54
     * @return mixed  Returns either the cached data or false
55
     */
56
    protected function _doFetch($id, $testCacheValidity = true)
57
    {
58
        return apc_fetch($id);
59
    }
60
 
61
    /**
62
     * Test if a cache record exists for the passed id
63
     *
64
     * @param string $id cache id
65
     * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
66
     */
67
    protected function _doContains($id)
68
    {
69
        $found = false;
70
        apc_fetch($id, $found);
71
        return $found;
72
    }
73
 
74
    /**
75
     * Save a cache record directly. This method is implemented by the cache
76
     * drivers and used in Doctrine_Cache_Driver::save()
77
     *
78
     * @param string $id        cache id
79
     * @param string $data      data to cache
80
     * @param int $lifeTime     if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
81
     * @return boolean true if no problem
82
     */
83
    protected function _doSave($id, $data, $lifeTime = false)
84
    {
85
        return apc_store($id, $data, $lifeTime);
86
    }
87
 
88
    /**
89
     * Remove a cache record directly. This method is implemented by the cache
90
     * drivers and used in Doctrine_Cache_Driver::delete()
91
     *
92
     * @param string $id cache id
93
     * @return boolean true if no problem
94
     */
95
    protected function _doDelete($id)
96
    {
97
        return apc_delete($id);
98
    }
99
 
100
    /**
101
     * Fetch an array of all keys stored in cache
102
     *
103
     * @return array Returns the array of cache keys
104
     */
105
    protected function _getCacheKeys()
106
    {
107
        $ci = apc_cache_info('user');
108
        $keys = array();
109
 
110
        foreach ($ci['cache_list'] as $entry) {
111
          $keys[] = $entry['info'];
112
        }
113
        return $keys;
114
    }
115
}