Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / libs / objectcache / CachedBagOStuff.php
blob60ec9222f022e7bbac58562a30e867dbe84ee185
1 <?php
2 /**
3 * Wrapper around a BagOStuff that caches data in memory
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.
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.
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
20 * @file
21 * @ingroup Cache
24 /**
25 * Wrapper around a BagOStuff that caches data in memory
27 * The differences between CachedBagOStuff and MultiWriteBagOStuff are:
28 * * CachedBagOStuff supports only one "backend".
29 * * There's a flag for writes to only go to the in-memory cache.
30 * * The in-memory cache is always updated.
31 * * Locks go to the backend cache (with MultiWriteBagOStuff, it would wind
32 * up going to the HashBagOStuff used for the in-memory cache).
34 * @ingroup Cache
36 class CachedBagOStuff extends HashBagOStuff {
37 /** @var BagOStuff */
38 protected $backend;
40 /**
41 * @param BagOStuff $backend Permanent backend to use
42 * @param array $params Parameters for HashBagOStuff
44 function __construct( BagOStuff $backend, $params = [] ) {
45 $this->backend = $backend;
46 parent::__construct( $params );
49 protected function doGet( $key, $flags = 0 ) {
50 $ret = parent::doGet( $key, $flags );
51 if ( $ret === false && !$this->hasKey( $key ) ) {
52 $ret = $this->backend->doGet( $key, $flags );
53 $this->set( $key, $ret, 0, self::WRITE_CACHE_ONLY );
55 return $ret;
58 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
59 parent::set( $key, $value, $exptime, $flags );
60 if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
61 $this->backend->set( $key, $value, $exptime, $flags & ~self::WRITE_CACHE_ONLY );
63 return true;
66 public function delete( $key, $flags = 0 ) {
67 unset( $this->bag[$key] );
68 if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
69 $this->backend->delete( $key );
72 return true;
75 public function setDebug( $bool ) {
76 parent::setDebug( $bool );
77 $this->backend->setDebug( $bool );
80 public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
81 return $this->backend->lock( $key, $timeout, $expiry, $rclass );
84 public function unlock( $key ) {
85 return $this->backend->unlock( $key );
88 public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
89 parent::deleteObjectsExpiringBefore( $date, $progressCallback );
90 return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback );
93 public function getLastError() {
94 return $this->backend->getLastError();
97 public function clearLastError() {
98 $this->backend->clearLastError();
101 public function modifySimpleRelayEvent( array $event ) {
102 return $this->backend->modifySimpleRelayEvent( $event );