aboutsummaryrefslogtreecommitdiffstats
path: root/includes/ObjectCache.php
diff options
context:
space:
mode:
authornobody <nobody@localhost>2004-06-27 00:05:32 +0000
committernobody <nobody@localhost>2004-06-27 00:05:32 +0000
commit0c1d741ff4792d486258b390cf50cf3f9e229511 (patch)
tree55961c46b433ade0739763bee2ba3c4843d13751 /includes/ObjectCache.php
parentd5c8171a3157337557bc54ecb730d7dd35778ca3 (diff)
parent1aaed5fd7c7f4d7ea7abbfc7915bab5954d60a30 (diff)
downloadmediawikicore-0c1d741ff4792d486258b390cf50cf3f9e229511.tar.gz
mediawikicore-0c1d741ff4792d486258b390cf50cf3f9e229511.zip
This commit was manufactured by cvs2svn to create tag1.3.0beta4a
'REL1_3_0beta4a'.
Diffstat (limited to 'includes/ObjectCache.php')
-rw-r--r--includes/ObjectCache.php56
1 files changed, 23 insertions, 33 deletions
diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php
index 00864c6b16b1..ce511ff37b10 100644
--- a/includes/ObjectCache.php
+++ b/includes/ObjectCache.php
@@ -1,4 +1,6 @@
<?php
+# $Id$
+#
# Copyright (C) 2003-2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/
#
@@ -69,8 +71,10 @@ class /* abstract */ BagOStuff {
}
function add($key, $value, $exptime=0) {
- if( $this->get($key) === false )
+ if( $this->get($key) == false ) {
$this->set($key, $value, $exptime);
+ return true;
+ }
}
function add_multi($hash, $exptime=0) {
@@ -114,7 +118,7 @@ class /* abstract */ BagOStuff {
function _debug($text) {
if($this->debugmode)
- echo "\ndebug: $text\n";
+ wfDebug("BagOStuff debug: $text\n");
}
}
@@ -187,9 +191,9 @@ class /* abstract */ SqlBagOStuff extends BagOStuff {
$this->_debug("get: ** error: " . $this->_dberror($res) . " **");
return false;
}
- if($arr = $this->_fetchrow($res)) {
- $this->_debug("get: retrieved data; exp time is " . $arr['exptime']);
- return unserialize($arr['value']);
+ if($row=$this->_fetchobject($res)) {
+ $this->_debug("get: retrieved data; exp time is " . $row->exptime);
+ return unserialize($row->value);
} else {
$this->_debug("get: no matching rows");
}
@@ -208,8 +212,8 @@ class /* abstract */ SqlBagOStuff extends BagOStuff {
}
$this->delete( $key );
$this->_query(
- "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2',$exp)",
- $key, serialize(&$value));
+ "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2','$exp')",
+ $key, serialize($value));
return true; /* ? */
}
@@ -230,7 +234,7 @@ class /* abstract */ SqlBagOStuff extends BagOStuff {
$sql);
}
$res = $this->_doquery($sql);
- if($res === false) {
+ if($res == false) {
$this->_debug("query failed: " . $this->_dberror($res));
}
return $res;
@@ -269,7 +273,8 @@ class /* abstract */ SqlBagOStuff extends BagOStuff {
function expireall() {
/* Remove any items that have expired */
- $this->_query( "DELETE FROM $0 WHERE exptime<=NOW()" );
+ $now=$this->_fromunixtime(time());
+ $this->_query( "DELETE FROM $0 WHERE exptime<'$now'" );
}
function deleteall() {
@@ -278,42 +283,27 @@ class /* abstract */ SqlBagOStuff extends BagOStuff {
}
}
-class MysqlBagOStuff extends SqlBagOStuff {
+class MediaWikiBagOStuff extends SqlBagOStuff {
function _doquery($sql) {
- return mysql_query($sql);
+ return wfQuery($sql, DB_READ, "MediaWikiBagOStuff:_doquery");
}
- function _fetchrow($result) {
- return mysql_fetch_array($result);
+ function _fetchobject($result) {
+ return wfFetchObject($result);
}
function _freeresult($result) {
- return mysql_free_result($result);
+ return wfFreeResult($result);
}
function _dberror($result) {
- if($result)
- return mysql_error($result);
- else
- return mysql_error();
+ return wfLastError();
}
-
function _maxdatetime() {
- return "'9999-12-31 12:59:59'";
+ return "9999-12-31 12:59:59";
}
-
function _fromunixtime($ts) {
- return "FROM_UNIXTIME($ts)";
+ return gmdate( "Y-m-d H:i:s", $ts );
}
-
function _strencode($s) {
- return mysql_escape_string($s);
- }
-}
-
-class MediaWikiBagOStuff extends MysqlBagOStuff {
- function _doquery($sql) {
- return wfQuery($sql, DB_READ, "MediaWikiBagOStuff:_doquery");
- }
- function _freeresult($result) {
- return wfFreeResult($result);
+ return wfStrEncode($s);
}
}