Skip to content

Commit bc644c2

Browse files
fajardoleoswashata
authored andcommitted
[updates-check] [api] [cache] Improved the updates check API response caching.
1 parent 0864963 commit bc644c2

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

includes/class-freemius.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20815,7 +20815,7 @@ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expir
2081520815
*
2081620816
* @return bool|FS_Plugin_Tag
2081720817
*/
20818-
function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
20818+
function get_update( $plugin_id = false, $flush = true, $expiration = FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION, $newer_than = false ) {
2081920819
$this->_logger->entrance();
2082020820

2082120821
if ( ! is_numeric( $plugin_id ) ) {
@@ -22484,7 +22484,7 @@ private function check_updates(
2248422484
$background = false,
2248522485
$plugin_id = false,
2248622486
$flush = true,
22487-
$expiration = WP_FS__TIME_24_HOURS_IN_SEC,
22487+
$expiration = FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION,
2248822488
$newer_than = false
2248922489
) {
2249022490
$this->_logger->entrance();

includes/class-fs-api.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,12 @@ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN
318318
$flush = true;
319319
}
320320

321-
$cached_result = self::$_cache->get( $cache_key );
321+
$has_valid_cache = self::$_cache->has_valid( $cache_key, $expiration );
322+
$cached_result = $has_valid_cache ?
323+
self::$_cache->get( $cache_key ) :
324+
null;
322325

323-
if ( $flush || ! self::$_cache->has_valid( $cache_key, $expiration ) ) {
326+
if ( $flush || is_null( $cached_result ) ) {
324327
$result = $this->call( $path );
325328

326329
if ( ! is_object( $result ) || isset( $result->error ) ) {

includes/class-fs-plugin-updater.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class FS_Plugin_Updater {
3737

3838
private static $_upgrade_basename = null;
3939

40+
const UPDATES_CHECK_CACHE_EXPIRATION = ( WP_FS__TIME_24_HOURS_IN_SEC / 24 );
41+
4042
#--------------------------------------------------------------------------------
4143
#region Singleton
4244
#--------------------------------------------------------------------------------
@@ -530,7 +532,7 @@ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
530532
$new_version = $this->_fs->get_update(
531533
false,
532534
fs_request_get_bool( 'force-check' ),
533-
WP_FS__TIME_24_HOURS_IN_SEC / 24,
535+
FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION,
534536
$current_plugin_version
535537
);
536538

@@ -1188,7 +1190,7 @@ private static function get_tested_wp_version( $tested_up_to ) {
11881190
* @return object
11891191
*/
11901192
private function get_latest_download_details( $addon_id = false, $newer_than = false, $fetch_readme = true ) {
1191-
return $this->_fs->_fetch_latest_version( $addon_id, true, WP_FS__TIME_24_HOURS_IN_SEC, $newer_than, $fetch_readme );
1193+
return $this->_fs->_fetch_latest_version( $addon_id, true, FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION, $newer_than, $fetch_readme );
11921194
}
11931195

11941196
/**

includes/fs-plugin-info-dialog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function _get_addon_info_filter( $data, $action = '', $args = null ) {
238238
$latest = $this->_fs->_fetch_latest_version(
239239
$selected_addon->id,
240240
true,
241-
WP_FS__TIME_24_HOURS_IN_SEC,
241+
FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION,
242242
$current_addon_version
243243
);
244244

start.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @var string
1717
*/
18-
$this_sdk_version = '2.7.0';
18+
$this_sdk_version = '2.7.0.1';
1919

2020
#region SDK Selection Logic --------------------------------------------------------------------
2121

templates/account.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* @var FS_Plugin_Tag $update
2323
*/
2424
$update = $fs->has_release_on_freemius() ?
25-
$fs->get_update( false, false, WP_FS__TIME_24_HOURS_IN_SEC / 24 ) :
26-
null;
25+
$fs->get_update( false, false ) :
26+
null;
2727

2828
if ( is_object($update) ) {
2929
/**

0 commit comments

Comments
 (0)