<?php
+/**
+ * Object caching using DBA backend.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Cache
+ */
/**
* Cache that uses DBA as a backend.
* writer locks. Intended for development use only, as a memcached workalike
* for systems that don't have it.
*
+ * On construction you can pass array( 'dir' => '/some/path' ); as a parameter
+ * to override the default DBA files directory (wfTempDir()).
+ *
* @ingroup Cache
*/
class DBABagOStuff extends BagOStuff {
var $mHandler, $mFile, $mReader, $mWriter, $mDisabled;
- public function __construct( $dir = false ) {
+ /**
+ * @param $params array
+ */
+ public function __construct( $params ) {
global $wgDBAhandler;
- if ( $dir === false ) {
- global $wgTmpDirectory;
- $dir = $wgTmpDirectory;
+ if ( !isset( $params['dir'] ) ) {
+ $params['dir'] = wfTempDir();
}
- $this->mFile = "$dir/mw-cache-" . wfWikiID();
+ $this->mFile = $params['dir']."/mw-cache-" . wfWikiID();
$this->mFile .= '.db';
wfDebug( __CLASS__ . ": using cache file {$this->mFile}\n" );
$this->mHandler = $wgDBAhandler;
/**
* Encode value and expiry for storage
+ * @param $value
+ * @param $expiry
+ *
+ * @return string
*/
function encode( $value, $expiry ) {
# Convert to absolute time
}
/**
- * @return list containing value first and expiry second
+ * @param $blob string
+ * @return array list containing value first and expiry second
*/
function decode( $blob ) {
if ( !is_string( $blob ) ) {
}
}
+ /**
+ * @return resource
+ */
function getReader() {
if ( file_exists( $this->mFile ) ) {
$handle = dba_open( $this->mFile, 'rl', $this->mHandler );
return $handle;
}
+ /**
+ * @return resource
+ */
function getWriter() {
$handle = dba_open( $this->mFile, 'cl', $this->mHandler );
return $handle;
}
+ /**
+ * @param $key string
+ * @return mixed|null|string
+ */
function get( $key ) {
wfProfileIn( __METHOD__ );
wfDebug( __METHOD__ . "($key)\n" );
return $val;
}
+ /**
+ * @param $key string
+ * @param $value mixed
+ * @param $exptime int
+ * @return bool
+ */
function set( $key, $value, $exptime = 0 ) {
wfProfileIn( __METHOD__ );
wfDebug( __METHOD__ . "($key)\n" );
return $ret;
}
+ /**
+ * @param $key string
+ * @param $time int
+ * @return bool
+ */
function delete( $key, $time = 0 ) {
wfProfileIn( __METHOD__ );
wfDebug( __METHOD__ . "($key)\n" );
return $ret;
}
+ /**
+ * @param $key string
+ * @param $value mixed
+ * @param $exptime int
+ * @return bool
+ */
function add( $key, $value, $exptime = 0 ) {
wfProfileIn( __METHOD__ );
return $ret;
}
+ /**
+ * @return Array
+ */
function keys() {
$reader = $this->getReader();
$k1 = dba_firstkey( $reader );
$result[] = $k1;
- while ( $key = dba_nextkey( $reader ) ) {
+ $key = dba_nextkey( $reader );
+ while ( $key ) {
$result[] = $key;
+ $key = dba_nextkey( $reader );
}
return $result;