| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: Array.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 |
* Array 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_Array extends Doctrine_Cache_Driver
|
|
|
35 |
{
|
|
|
36 |
/**
|
|
|
37 |
* @var array $data an array of cached data
|
|
|
38 |
*/
|
|
|
39 |
protected $data = array();
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Fetch a cache record from this cache driver instance
|
|
|
43 |
*
|
|
|
44 |
* @param string $id cache id
|
|
|
45 |
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
|
|
|
46 |
* @return mixed Returns either the cached data or false
|
|
|
47 |
*/
|
|
|
48 |
protected function _doFetch($id, $testCacheValidity = true)
|
|
|
49 |
{
|
|
|
50 |
if (isset($this->data[$id])) {
|
|
|
51 |
return $this->data[$id];
|
|
|
52 |
}
|
|
|
53 |
return false;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Test if a cache record exists for the passed id
|
|
|
58 |
*
|
|
|
59 |
* @param string $id cache id
|
|
|
60 |
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
|
61 |
*/
|
|
|
62 |
protected function _doContains($id)
|
|
|
63 |
{
|
|
|
64 |
return isset($this->data[$id]);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Save a cache record directly. This method is implemented by the cache
|
|
|
69 |
* drivers and used in Doctrine_Cache_Driver::save()
|
|
|
70 |
*
|
|
|
71 |
* @param string $id cache id
|
|
|
72 |
* @param string $data data to cache
|
|
|
73 |
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
|
74 |
* @return boolean true if no problem
|
|
|
75 |
*/
|
|
|
76 |
protected function _doSave($id, $data, $lifeTime = false)
|
|
|
77 |
{
|
|
|
78 |
$this->data[$id] = $data;
|
|
|
79 |
|
|
|
80 |
return true;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Remove a cache record directly. This method is implemented by the cache
|
|
|
85 |
* drivers and used in Doctrine_Cache_Driver::delete()
|
|
|
86 |
*
|
|
|
87 |
* @param string $id cache id
|
|
|
88 |
* @return boolean true if no problem
|
|
|
89 |
*/
|
|
|
90 |
protected function _doDelete($id)
|
|
|
91 |
{
|
|
|
92 |
$exists = isset($this->data[$id]);
|
|
|
93 |
|
|
|
94 |
unset($this->data[$id]);
|
|
|
95 |
|
|
|
96 |
return $exists;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Fetch an array of all keys stored in cache
|
|
|
101 |
*
|
|
|
102 |
* @return array Returns the array of cache keys
|
|
|
103 |
*/
|
|
|
104 |
protected function _getCacheKeys()
|
|
|
105 |
{
|
|
|
106 |
return array_keys($this->data);
|
|
|
107 |
}
|
|
|
108 |
}
|