Skip to content

Commit

Permalink
fixed expiry time and cache retrieval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
naxvog committed Dec 3, 2019
1 parent 8a78d81 commit a38df74
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
11 changes: 7 additions & 4 deletions includes/class-redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function add(
) {
return [
self::set( $key, $value, self::expiry_time() ),
self::set( $key . '-modified', time(), self::expiry_time() ),
self::set( "{$key}-modified", time(), self::expiry_time() ),
];
}

Expand Down Expand Up @@ -338,15 +338,18 @@ protected static function lua_flush_closure(
}

/**
* Retrieved set WP Rocket expiry time
* Retrieves set WP Rocket expiry time in hours
*
* @since 1.0.0
* @return int
* @return int Expiry in hours
*/
protected static function expiry_time() {
static $expiry;
if ( ! isset( $expiry ) ) {
$expiry = get_rocket_purge_cron_interval();
$hours = function_exists( 'get_rocket_option' )
? get_rocket_option( 'purge_cron_interval' )
: 10;
$expiry = $hours * HOUR_IN_SECONDS;
}
return $expiry;
}
Expand Down
8 changes: 6 additions & 2 deletions overrides/wp-rocket/buffer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ function filemtime( $filename ) {
*/
function readfile( $filename, $use_include_path = false, $context = null ) {
if ( Redis::is_active() ) {
return Redis::get( $filename );
$content = Redis::get( $filename );
echo $content;
return strlen( $content ) ?: false;
}
return \readfile( $filename, $use_include_path, $context );
}
Expand All @@ -77,7 +79,9 @@ function readfile( $filename, $use_include_path = false, $context = null ) {
*/
function readgzfile( $filename, $use_include_path = 0 ) {
if ( Redis::is_active() ) {
return Redis::get( $filename );
$content = Redis::get( $filename );
echo gzdecode( $content );
return strlen( $content ) ?: false;
}
return \readgzfile( $filename, $use_include_path );
}
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Tags: redis, cache, wp-rocket
Tested up to: 5.2
Requires PHP: 7.0
Stable tag: 1.0.0
Stable tag: 1.0.2
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -22,6 +22,10 @@ It therefore requires a working Redis server.

== Changelog ==

= 1.0.2 =
* Fixed the cache retrieval override functions
* Fixed the expiry time method of the redis class as WP Rocket changed its API

= 1.0.1 =
* Allows for the translation of the plugin
* Added German translations
Expand Down
22 changes: 15 additions & 7 deletions wpr-redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Rocket Redis
* Plugin URI: https://github.com/naxvog/wpr-redis/
* Description: Addon to WP Rocket that allows storage of cache files in Redis.
* Version: 1.0.1
* Version: 1.0.2
* Author: naxvog <naxvog@users.noreply.github.com>
* Author URI: https://github.com/naxvog/
* Text Domain: wpr-redis
Expand Down Expand Up @@ -34,12 +34,20 @@
$loader->add_namespace( 'WPR_Redis', WPR_REDIS_INCLUDE_PATH );
$loader->add_namespace( 'WP_Rocket', WPR_REDIS_OVERRIDE_PATH . '/wp-rocket' );

function wpr_redis() {
static $instance;
if ( ! isset( $instance ) ) {
$instance = new WPR_Redis\WPR_Redis();
if ( ! function_exists( 'wpr_redis' ) ) :
/**
* Instance function to initialize and/or retrieve the plugin instance.
*
* @since 1.0.0
* @return \WPR_Redis\WPR_Redis
*/
function wpr_redis() {
static $instance;
if ( ! isset( $instance ) ) {
$instance = new WPR_Redis\WPR_Redis();
}
return $instance;
}
return $instance;
}
endif;

wpr_redis();

0 comments on commit a38df74

Please sign in to comment.