tosfos has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247924
Change subject: Switch cache to use internal ObjectCache
......................................................................
Switch cache to use internal ObjectCache
* deprecate $wgFlickrAPICache
* deprecate FlickrAPI table
Change-Id: I756771a29f374731c6b975b8bb1067c1ecd01c22
---
M FlickrAPI.hooks.php
M FlickrAPI.php
D FlickrAPI.sql
M FlickrAPICache.php
4 files changed, 21 insertions(+), 48 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlickrAPI
refs/changes/24/247924/1
diff --git a/FlickrAPI.hooks.php b/FlickrAPI.hooks.php
index e5b1280..1a8645e 100644
--- a/FlickrAPI.hooks.php
+++ b/FlickrAPI.hooks.php
@@ -118,7 +118,6 @@
*
* @global string $wgFlickrAPIKey
* @global string $wgFlickrAPISecret
- * @global boolean $wgFlickrAPICache
* @global boolean $wgUseFileCache
* @global string $wgFileCacheDirectory
* @param string $optionsString
@@ -127,8 +126,7 @@
* @throws MWException
*/
private static function getOutput( $optionsString, Parser $parser ) {
- global $wgFlickrAPIKey, $wgFlickrAPISecret,
- $wgFlickrAPICache, $wgUseFileCache, $wgFileCacheDirectory;
+ global $wgFlickrAPIKey, $wgFlickrAPISecret, $wgUseFileCache,
$wgFileCacheDirectory;
wfProfileIn( __METHOD__ );
@@ -147,14 +145,13 @@
}
$phpFlickr = new phpFlickr( $wgFlickrAPIKey, $wgFlickrAPISecret
);
- // Decide which cache to use, if any.
- if ( $wgFlickrAPICache ) {
- if ( $wgUseFileCache ) {
- $phpFlickr->enableCache( 'fs',
$wgFileCacheDirectory );
- } else {
- $phpFlickr->enableCache( 'custom',
- array( 'FlickrAPICache::getCache',
'FlickrAPICache::setCache' ) );
- }
+
+ // Decide which cache to use
+ if ( $wgUseFileCache ) {
+ $phpFlickr->enableCache( 'fs', $wgFileCacheDirectory );
+ } else {
+ $phpFlickr->enableCache( 'custom',
+ array( 'FlickrAPICache::getCache',
'FlickrAPICache::setCache' ) );
}
$info = $phpFlickr->photos_getInfo( $options['id'] );
diff --git a/FlickrAPI.php b/FlickrAPI.php
index ddb4f05..9f13c70 100644
--- a/FlickrAPI.php
+++ b/FlickrAPI.php
@@ -16,7 +16,7 @@
'author' => array(
'Ike Hecht',
),
- 'version' => '0.1.1',
+ 'version' => '1.0.0',
'url' => 'https://www.mediawiki.org/wiki/Extension:FlickrAPI',
'descriptionmsg' => 'flickrapi-desc',
);
@@ -38,13 +38,7 @@
return true;
};
-$wgHooks['LoadExtensionSchemaUpdates'][] = function ( DatabaseUpdater $updater
) {
- $updater->addExtensionTable( FlickrAPICache::TABLE, __DIR__ .
'/FlickrAPI.sql', true );
- return true;
-};
-
/* Configuration */
$wgFlickrAPIKey = '';
$wgFlickrAPISecret = '';
-$wgFlickrAPICache = ( $wgMainCacheType === CACHE_NONE ) ? false : true;
$wgFlickrAPIDefaults = array( 'type' => 'frameless', 'location' => 'right',
'size' => '-' );
diff --git a/FlickrAPI.sql b/FlickrAPI.sql
deleted file mode 100644
index 9ef4430..0000000
--- a/FlickrAPI.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-CREATE TABLE IF NOT EXISTS /*_*/FlickrAPI (
- `request` varchar(128) NOT NULL,
- `response` mediumtext NOT NULL,
- `expiration` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- UNIQUE KEY `request` (`request`)
-) /*$wgDBTableOptions*/;
diff --git a/FlickrAPICache.php b/FlickrAPICache.php
index ea62be1..8cb3ed3 100644
--- a/FlickrAPICache.php
+++ b/FlickrAPICache.php
@@ -6,7 +6,6 @@
* @author Ike Hecht
*/
class FlickrAPICache {
- const TABLE = 'FlickrAPI';
/**
* Get this call from db cache
@@ -15,16 +14,12 @@
* @return string|boolean
*/
public static function getCache( $reqhash ) {
- $dbr = wfGetDB( DB_SLAVE );
- $conds = array( 'request' => $reqhash, 'CURRENT_TIMESTAMP <
expiration' );
- $result = $dbr->select( self::TABLE, 'response', $conds,
__METHOD__ );
-
- $row = $result->fetchObject();
- if ( $row ) {
- return ( $row->response );
- } else {
- return false;
- }
+ $cache = wfGetCache( CACHE_ANYTHING );
+ $key = wfMemcKey( 'flickrapi', $reqhash );
+ $cached = $cache->get( $key );
+ wfDebugLog( "FlickrAPI", __METHOD__ . ": got " . var_export(
$cached, true ) .
+ " from cache." );
+ return $cached;
}
/**
@@ -34,20 +29,13 @@
* @param string $response
* @param integer $cache_expire
* @return boolean
- * @throws MWException
*/
public static function setCache( $reqhash, $response, $cache_expire ) {
- $dbw = wfGetDB( DB_MASTER );
- $data = array(
- 'request' => $reqhash,
- 'response' => $response,
- 'expiration' => $dbw->encodeExpiry( wfTimestamp( TS_MW,
time() + $cache_expire ) )
- );
- $result = $dbw->upsert( self::TABLE, $data, array( 'request' ),
$data, __METHOD__ );
- if ( !$result ) {
- throw new MWException( 'Set Cache failed' );
- }
-
- return $result;
+ $cache = wfGetCache( CACHE_ANYTHING );
+ $key = wfMemcKey( 'flickrapi', $reqhash );
+ wfDebugLog( "FlickrAPI",
+ __METHOD__ . ": caching " . var_export( $response, true
) .
+ " from Flickr." );
+ return $cache->set( $key, $response, $cache_expire );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/247924
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I756771a29f374731c6b975b8bb1067c1ecd01c22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlickrAPI
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits