Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / libs / objectcache / HashBagOStuff.php
1 <?php
2 /**
3 * Object caching using PHP arrays.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24 /**
25 * This is a test of the interface, mainly. It stores things in an associative
26 * array, which is not going to persist between program runs.
27 *
28 * @ingroup Cache
29 */
30 class HashBagOStuff extends BagOStuff {
31 /** @var array */
32 protected $bag;
33
34 function __construct( $params = array() ) {
35 parent::__construct( $params );
36 $this->bag = array();
37 }
38
39 protected function expire( $key ) {
40 $et = $this->bag[$key][1];
41
42 if ( ( $et == 0 ) || ( $et > time() ) ) {
43 return false;
44 }
45
46 $this->delete( $key );
47
48 return true;
49 }
50
51 public function get( $key, &$casToken = null, $flags = 0 ) {
52 if ( !isset( $this->bag[$key] ) ) {
53 return false;
54 }
55
56 if ( $this->expire( $key ) ) {
57 return false;
58 }
59
60 $casToken = $this->bag[$key][0];
61
62 return $this->bag[$key][0];
63 }
64
65 public function set( $key, $value, $exptime = 0 ) {
66 $this->bag[$key] = array( $value, $this->convertExpiry( $exptime ) );
67 return true;
68 }
69
70 function delete( $key ) {
71 unset( $this->bag[$key] );
72
73 return true;
74 }
75 }