Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constant to set default cache expire #263

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down