Jqnatividad has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71722
Change subject: Added "cache seconds" parameter to #get_web_data to add per
query cache settings. Some APIs are fairly static (e.g. Wikipedia places) and
some are very dynamic (e.g. Craiglists listings) and having one global cache
expire time was insufficient.
......................................................................
Added "cache seconds" parameter to #get_web_data to add per query cache
settings.
Some APIs are fairly static (e.g. Wikipedia places) and some are very dynamic
(e.g. Craiglists listings) and having one global cache expire time was
insufficient.
Change-Id: I7e7b24f985c019fbcdcf16c765a55f5f2059773e
---
M ED_ParserFunctions.php
M ED_Utils.php
2 files changed, 15 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData
refs/changes/22/71722/1
diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php
index 752b4a7..accab12 100644
--- a/ED_ParserFunctions.php
+++ b/ED_ParserFunctions.php
@@ -115,7 +115,7 @@
* Render the #get_web_data parser function
*/
static function doGetWebData( &$parser ) {
- global $edgCurPageName, $edgValues;
+ global $edgCurPageName, $edgValues, $edgCacheExpireTime;
// If we're handling multiple pages, reset $edgValues
// when we move from one page to another.
@@ -164,8 +164,15 @@
return;
}
+ if ( array_key_exists( 'cache seconds', $args) ) {
+ // set cache expire time
+ $cacheExpireTime = $args['cache seconds'];
+ } else {
+ $cacheExpireTime = $edgCacheExpireTime;
+ }
+
$postData = array_key_exists( 'post data', $args ) ?
$args['post data'] : '';
- $external_values = EDUtils::getDataFromURL( $url, $format,
$mappings, $postData );
+ $external_values = EDUtils::getDataFromURL( $url, $format,
$mappings, $postData, $cacheExpireTime );
if ( is_string( $external_values ) ) {
// It's an error message - just display it on the
// screen.
diff --git a/ED_Utils.php b/ED_Utils.php
index 45e7744..797f39c 100644
--- a/ED_Utils.php
+++ b/ED_Utils.php
@@ -699,10 +699,10 @@
return $values;
}
- static function fetchURL( $url, $post_vars = array(), $get_fresh =
false, $try_count = 1 ) {
+ static function fetchURL( $url, $post_vars = array(), $cacheExpireTime
= 0, $get_fresh = false, $try_count = 1 ) {
$dbr = wfGetDB( DB_SLAVE );
global $edgStringReplacements, $edgCacheTable,
- $edgCacheExpireTime, $edgAllowSSL;
+ $edgAllowSSL;
if ( $post_vars ) {
return Http::post( $url, array( 'postData' =>
$post_vars ) );
@@ -729,7 +729,7 @@
// check the cache (only the first 254 chars of the url)
$row = $dbr->selectRow( $edgCacheTable, '*', array( 'url' =>
substr( $url, 0, 254 ) ), 'EDUtils::fetchURL' );
- if ( $row && ( ( time() - $row->req_time ) >
$edgCacheExpireTime ) ) {
+ if ( $row && ( ( time() - $row->req_time ) > $cacheExpireTime )
) {
$get_fresh = true;
}
@@ -746,7 +746,7 @@
return '';
}
$try_count++;
- return self::fetchURL( $url, $post_vars,
$get_fresh, $try_count );
+ return self::fetchURL( $url, $post_vars,
$cacheExpireTime, $get_fresh, $try_count );
}
if ( $page != '' ) {
$dbw = wfGetDB( DB_MASTER );
@@ -788,8 +788,8 @@
}
}
- static public function getDataFromURL( $url, $format, $mappings,
$postData = null ) {
- $url_contents = self::fetchURL( $url, $postData );
+ static public function getDataFromURL( $url, $format, $mappings,
$postData = null, $cacheExpireTime ) {
+ $url_contents = self::fetchURL( $url, $postData,
$cacheExpireTime );
// exit if there's nothing there
if ( empty( $url_contents ) )
return array();
--
To view, visit https://gerrit.wikimedia.org/r/71722
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e7b24f985c019fbcdcf16c765a55f5f2059773e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ExternalData
Gerrit-Branch: master
Gerrit-Owner: Jqnatividad <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits