From c97318110c8505b408c7389d04ecaabefdea069e Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 3 Jul 2008 18:24:08 +0000 Subject: [PATCH] Refactor caching to utilize $wgMemc rather than the transcache table. Thanks to ialex and VasilievVV. :) --- includes/filerepo/File.php | 39 ++++++---------------------------- includes/filerepo/FileRepo.php | 2 +- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index af5519c1e9..169ae86884 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -1062,58 +1062,31 @@ abstract class File { * Get the HTML text of the description page, if available */ function getDescriptionText() { + global $wgMemc, $wgTranscludeCacheExpiry; if ( !$this->repo->fetchDescription ) { return false; } $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() ); if ( $renderUrl ) { - if ( $this->repo->useTransCache ) { + if ( $this->repo->useLocalCache ) { wfDebug("Attempting to get the description from the transwiki cache..."); - $this->purgeTransCacheEntries(); - $dbr = wfGetDB(DB_SLAVE); - $obj = $dbr->selectRow('transcache', array('tc_contents'), - array('tc_url' => $renderUrl)); + $key = md5($renderUrl); + $obj = $wgMemc->get($key); if ($obj) { wfDebug("success!\n"); - return $obj->tc_contents; + return $obj; } wfDebug("miss\n"); } wfDebug( "Fetching shared description from $renderUrl\n" ); $res = Http::get( $renderUrl ); - if ( $res && $this->repo->useTransCache ) $this->addToTransCache( $res, $renderUrl ); + if ( $res && $this->repo->useLocalCache ) $wgMemc->set( $key, $res, time() + $wgTranscludeCacheExpiry ); return $res; } else { return false; } } - /** - * Purge expired transcache entries - */ - function purgeTranscacheEntries() { - global $wgTranscludeCacheExpiry; - $dbw = wfGetDB( DB_MASTER ); - $table = $dbw->tableName('transcache'); - $expiry = $dbw->addQuotes(time() - $wgTranscludeCacheExpiry); - $res = $dbw->delete( $table, array("tc_time < $expiry"), __METHOD__ ); - if ($res) wfDebug("purging old transcache entries..."); - } - - /** - * Add new transcache entry - * - * @param string $text Text to add to the cache - * @param string $url Url we're caching - */ - function addToTransCache( $text, $url ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->replace('transcache', array('tc_url'), array( - 'tc_url' => $url, - 'tc_time' => time(), - 'tc_contents' => $text)); - } - /** * Get discription of file revision * STUB diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 93089a8553..ca79685b2d 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -30,7 +30,7 @@ abstract class FileRepo { // Optional settings $this->initialCapital = true; // by default foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', - 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 'useTransCache' ) as $var ) + 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 'useLocalCache' ) as $var ) { if ( isset( $info[$var] ) ) { $this->$var = $info[$var]; -- 2.20.1