* backends for local hash array and SQL table included:
* <code>
* $bag = new HashBagOStuff();
- * $bag = new MysqlBagOStuff($tablename); # connect to db first
+ * $bag = new MediaWikiBagOStuff($tablename); # connect to db first
* </code>
*
+ * @atttogroup Cache
*/
class BagOStuff {
var $debugmode;
/**
* Functional versions!
- * @todo document
+ * This is a test of the interface, mainly. It stores things in an associative
+ * array, which is not going to persist between program runs.
+ *
+ * @atttogroup Cache
*/
class HashBagOStuff extends BagOStuff {
- /*
- This is a test of the interface, mainly. It stores
- things in an associative array, which is not going to
- persist between program runs.
- */
var $bag;
function __construct() {
}
}
-/*
-CREATE TABLE objectcache (
- keyname char(255) binary not null default '',
- value mediumblob,
- exptime datetime,
- unique key (keyname),
- key (exptime)
-);
-*/
-
/**
- * @todo document
- * @abstract
+ * Generic class to store objects in a database
+ *
+ * @atttogroup Cache
*/
abstract class SqlBagOStuff extends BagOStuff {
var $table;
var $lastexpireall = 0;
+ /**
+ * Constructor
+ *
+ * @param string $tablename name of the table to use
+ */
function __construct($tablename = 'objectcache') {
$this->table = $tablename;
}
}
function set($key,$value,$exptime=0) {
- if ( wfReadOnly() ) {
+ if ( $this->_readonly() ) {
return false;
}
$exptime = intval($exptime);
}
function delete($key,$time=0) {
- if ( wfReadOnly() ) {
+ if ( $this->_readonly() ) {
return false;
}
$this->_query(
abstract function _doinsert($table, $vals);
abstract function _doquery($sql);
+ abstract function _readonly();
+
function _freeresult($result) {
/* stub */
return false;
function expireall() {
/* Remove any items that have expired */
- if ( wfReadOnly() ) {
+ if ( $this->_readonly() ) {
return false;
}
$now = $this->_fromunixtime( time() );
function deleteall() {
/* Clear *all* items from cache table */
- if ( wfReadOnly() ) {
+ if ( $this->_readonly() ) {
return false;
}
$this->_query( "DELETE FROM $0" );
}
/**
- * @todo document
+ * Stores objects in the main database of the wiki
+ *
+ * @atttogroup Cache
*/
class MediaWikiBagOStuff extends SqlBagOStuff {
var $tableInitialised = false;
+ function _getDB(){
+ static $db;
+ if( !isset( $db ) )
+ $db = wfGetDB( DB_MASTER );
+ return $db;
+ }
function _doquery($sql) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->query($sql, 'MediaWikiBagOStuff::_doquery');
+ return $this->_getDB()->query( $sql, __METHOD__ );
}
function _doinsert($t, $v) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->insert($t, $v, 'MediaWikiBagOStuff::_doinsert',
- array( 'IGNORE' ) );
+ return $this->_getDB()->insert($t, $v, __METHOD__, array( 'IGNORE' ) );
}
function _fetchobject($result) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->fetchObject($result);
+ return $this->_getDB()->fetchObject($result);
}
function _freeresult($result) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->freeResult($result);
+ return $this->_getDB()->freeResult($result);
}
function _dberror($result) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->lastError();
+ return $this->_getDB()->lastError();
}
function _maxdatetime() {
if ( time() > 0x7fffffff ) {
}
}
function _fromunixtime($ts) {
- $dbw = wfGetDB(DB_MASTER);
- return $dbw->timestamp($ts);
+ return $this->_getDB()->timestamp($ts);
+ }
+ function _readonly(){
+ return wfReadOnly();
}
function _strencode($s) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->strencode($s);
+ return $this->_getDB()->strencode($s);
}
function _blobencode($s) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->encodeBlob($s);
+ return $this->_getDB()->encodeBlob($s);
}
function _blobdecode($s) {
- $dbw = wfGetDB( DB_MASTER );
- return $dbw->decodeBlob($s);
+ return $this->_getDB()->decodeBlob($s);
}
function getTableName() {
if ( !$this->tableInitialised ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->_getDB();
/* This is actually a hack, we should be able
to use Language classes here... or not */
if (!$dbw)
* that Turck's serializer is faster, so a possible future extension would be
* to use it for arrays but not for objects.
*
+ * @atttogroup Cache
*/
class TurckBagOStuff extends BagOStuff {
function get($key) {
/**
* This is a wrapper for APC's shared memory functions
*
+ * @atttogroup Cache
*/
class APCBagOStuff extends BagOStuff {
function get($key) {
* This is basically identical to the Turck MMCache version,
* mostly because eAccelerator is based on Turck MMCache.
*
+ * @atttogroup Cache
*/
class eAccelBagOStuff extends BagOStuff {
function get($key) {
/**
* Wrapper for XCache object caching functions; identical interface
* to the APC wrapper
+ *
+ * @atttogroup Cache
*/
class XCacheBagOStuff extends BagOStuff {
/**
* @todo document
+ * @atttogroup Cache
*/
class DBABagOStuff extends BagOStuff {
var $mHandler, $mFile, $mReader, $mWriter, $mDisabled;