- function SqlBagOStuff($tablename = 'objectcache') {
- $this->table = $tablename;
- }
-
- function get($key) {
- /* expire old entries if any */
- $this->garbageCollect();
-
- $res = $this->_query(
- "SELECT value,exptime FROM $0 WHERE keyname='$1'", $key);
- if(!$res) {
- $this->_debug("get: ** error: " . $this->_dberror($res) . " **");
- return false;
- }
- if($row=$this->_fetchobject($res)) {
- $this->_debug("get: retrieved data; exp time is " . $row->exptime);
- return $this->_unserialize($row->value);
- } else {
- $this->_debug('get: no matching rows');
- }
- return false;
- }
-
- function set($key,$value,$exptime=0) {
- $exptime = intval($exptime);
- if($exptime < 0) $exptime = 0;
- if($exptime == 0) {
- $exp = $this->_maxdatetime();
- } else {
- if($exptime < 3600*24*30)
- $exptime += time();
- $exp = $this->_fromunixtime($exptime);
- }
- $this->delete( $key );
- $this->_query(
- "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2','$exp')",
- $key, $this->_serialize($value));
- return true; /* ? */
- }
-
- function delete($key,$time=0) {
- $this->_query(
- "DELETE FROM $0 WHERE keyname='$1'", $key );
- return true; /* ? */
- }
-
- function getTableName() {
- return $this->table;
- }
-
- function _query($sql) {
- $reps = func_get_args();
- $reps[0] = $this->getTableName();
- // ewwww
- for($i=0;$i<count($reps);$i++) {
- $sql = str_replace(
- '$' . $i,
- $this->_strencode($reps[$i]),
- $sql);
- }
- $res = $this->_doquery($sql);
- if($res == false) {
- $this->_debug('query failed: ' . $this->_dberror($res));
- }
- return $res;
- }
-
- function _strencode($str) {
- /* Protect strings in SQL */
- return str_replace( "'", "''", $str );
- }
-
- function _doquery($sql) {
- die( 'abstract function SqlBagOStuff::_doquery() must be defined' );
- }
-
- function _fetchrow($res) {
- die( 'abstract function SqlBagOStuff::_fetchrow() must be defined' );
- }
-
- function _freeresult($result) {
- /* stub */
- return false;
- }
-
- function _dberror($result) {
- /* stub */
- return 'unknown error';
- }
-
- function _maxdatetime() {
- die( 'abstract function SqlBagOStuff::_maxdatetime() must be defined' );
- }
-
- function _fromunixtime() {
- die( 'abstract function SqlBagOStuff::_fromunixtime() must be defined' );
- }
-
- function garbageCollect() {
- /* Ignore 99% of requests */
- if ( !mt_rand( 0, 100 ) ) {
- $nowtime = time();
- /* Avoid repeating the delete within a few seconds */
- if ( $nowtime > ($this->lastexpireall + 1) ) {
- $this->lastexpireall = $nowtime;
- $this->expireall();
+ $wgCaches[CACHE_DB] = new MemCachedClientforWiki(
+ array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
+ $cache =& $wgCaches[CACHE_DB];
+ $cache->set_servers( $wgMemCachedServers );
+ $cache->set_debug( $wgMemCachedDebug );
+ }
+ } elseif ( $type == CACHE_ACCEL ) {
+ if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
+ if ( function_exists( 'eaccelerator_get' ) ) {
+ $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
+ } elseif ( function_exists( 'apc_fetch') ) {
+ $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
+ } elseif ( function_exists( 'mmcache_get' ) ) {
+ $wgCaches[CACHE_ACCEL] = new TurckBagOStuff;
+ } else {
+ $wgCaches[CACHE_ACCEL] = false;