From a466ccdda87ab12c6da605d65b2a9fd12e009792 Mon Sep 17 00:00:00 2001 From: Jim van der Voort Date: Fri, 10 Jan 2020 15:39:16 +0100 Subject: [PATCH 1/2] Add constant to set default cache expire --- object-cache.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/object-cache.php b/object-cache.php index 5c12e94..79b56d0 100644 --- a/object-cache.php +++ b/object-cache.php @@ -17,6 +17,10 @@ define( 'WP_REDIS_USE_CACHE_GROUPS', false ); } +if ( ! defined( 'WP_REDIS_DEFAULT_EXPIRE_SECONDS' ) ) { + define( 'WP_REDIS_DEFAULT_EXPIRE_SECONDS', 0 ); +} + /** * Adds data to the cache, if the cache key doesn't already exist. * @@ -29,7 +33,7 @@ * @param int $expire When the cache data should be expired * @return bool False if cache key and group already exist, true on success */ -function wp_cache_add( $key, $data, $group = '', $expire = 0 ) { +function wp_cache_add( $key, $data, $group = '', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { global $wp_object_cache; return $wp_object_cache->add( $key, $data, $group, (int) $expire ); @@ -171,7 +175,7 @@ function wp_cache_init() { * @param int $expire When to expire the cache contents * @return bool False if not exists, true if contents were replaced */ -function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { +function wp_cache_replace( $key, $data, $group = '', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { global $wp_object_cache; return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); @@ -189,7 +193,7 @@ function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { * @param int $expire When to expire the cache contents * @return bool False on failure, true on success */ -function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { +function wp_cache_set( $key, $data, $group = '', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { global $wp_object_cache; return $wp_object_cache->set( $key, $data, $group, (int) $expire ); @@ -383,7 +387,7 @@ class WP_Object_Cache { * @param int $expire When to expire the cache contents * @return bool False if cache key and group already exist, true on success */ - public function add( $key, $data, $group = 'default', $expire = 0 ) { + public function add( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { if ( empty( $group ) ) { $group = 'default'; @@ -708,7 +712,7 @@ public function incr( $key, $offset = 1, $group = 'default' ) { * @param int $expire When to expire the cache contents * @return bool False if not exists, true if contents were replaced */ - public function replace( $key, $data, $group = 'default', $expire = 0 ) { + public function replace( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { if ( empty( $group ) ) { $group = 'default'; @@ -748,7 +752,7 @@ public function reset() { * @param int $expire TTL for the data, in seconds * @return bool Always returns true */ - public function set( $key, $data, $group = 'default', $expire = 0 ) { + public function set( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT_EXPIRE_SECONDS ) { if ( empty( $group ) ) { $group = 'default'; From a49f92b58baa717b4942a9356a14ec1441f49b59 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 10 Jan 2020 08:05:06 -0800 Subject: [PATCH 2/2] Update README for v0.8.1 --- README.md | 5 ++++- readme.txt | 5 ++++- wp-redis.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7e495e..9b5ad53 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **Tags:** cache, plugin, redis **Requires at least:** 3.0.1 **Tested up to:** 5.3 -**Stable tag:** 0.8.0 +**Stable tag:** 0.8.1 **License:** GPLv2 or later **License URI:** http://www.gnu.org/licenses/gpl-2.0.html @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a ## Changelog ## +### 0.8.1 (January 10, 2020) ### +* Adds `WP_REDIS_DEFAULT_EXPIRE_SECONDS` constant to set default cache expire value [[#264](https://github.com/pantheon-systems/wp-redis/pull/264)]. + ### 0.8.0 (January 6, 2020) ### * Uses `flushdb` instead of `flushAll` to avoid flushing the entire Redis instance [[#259](https://github.com/pantheon-systems/wp-redis/pull/259)]. diff --git a/readme.txt b/readme.txt index 765dfc9..c00a36a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: getpantheon, danielbachhuber, mboynes, Outlandish Josh Tags: cache, plugin, redis Requires at least: 3.0.1 Tested up to: 5.3 -Stable tag: 0.8.0 +Stable tag: 0.8.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a == Changelog == += 0.8.1 (January 10, 2020) = +* Adds `WP_REDIS_DEFAULT_EXPIRE_SECONDS` constant to set default cache expire value [[#264](https://github.com/pantheon-systems/wp-redis/pull/264)]. + = 0.8.0 (January 6, 2020) = * Uses `flushdb` instead of `flushAll` to avoid flushing the entire Redis instance [[#259](https://github.com/pantheon-systems/wp-redis/pull/259)]. diff --git a/wp-redis.php b/wp-redis.php index ceb012b..64c9f43 100644 --- a/wp-redis.php +++ b/wp-redis.php @@ -3,7 +3,7 @@ * Plugin Name: WP Redis * Plugin URI: http://github.com/pantheon-systems/wp-redis/ * Description: WordPress Object Cache using Redis. Requires the PhpRedis extension (https://github.com/phpredis/phpredis). - * Version: 0.8.0 + * Version: 0.8.1 * Author: Pantheon, Josh Koenig, Matthew Boynes, Daniel Bachhuber, Alley Interactive * Author URI: https://pantheon.io/ */