Skip to content
Open
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
38 changes: 35 additions & 3 deletions includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,9 @@ protected function add_multiple_at_once( array $data, $group = 'default', $expir

$san_key = $this->sanitize_key_part( $key );
$derived_key = $derived_keys[ $key ] = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

$args = [ $derived_key, $this->maybe_serialize( $value ) ];

Expand Down Expand Up @@ -1313,6 +1316,9 @@ protected function add_or_replace( $add, $key, $value, $group = 'default', $expi
$san_group = $this->sanitize_key_part( $group );

$derived_key = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

// Save if group not excluded and redis is up.
if ( ! $this->is_ignored_group( $san_group ) && $this->redis_status() ) {
Expand Down Expand Up @@ -1404,6 +1410,9 @@ public function delete( $key, $group = 'default', $deprecated = false ) {
$san_group = $this->sanitize_key_part( $group );

$derived_key = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->srem(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

if ( array_key_exists( $derived_key, $this->cache ) ) {
unset( $this->cache[ $derived_key ] );
Expand Down Expand Up @@ -1639,11 +1648,22 @@ public function flush() {
$start_time = microtime( true );

if ( $salt && $selective ) {
$script = $this->get_flush_closure( $salt );
$results = $this->execute_lua_script( $script );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$results = $this->redis->smembers(WP_REDIS_SERVERLESS_WORKAROUND);
foreach ($results as $key) {
$this->redis->srem(WP_REDIS_SERVERLESS_WORKAROUND, $key);
$this->redis->del($key);
}
if (empty($results)) {
return false;
}
} else {
$script = $this->get_flush_closure($salt);
$results = $this->execute_lua_script($script);

if ( empty( $results ) ) {
if (empty($results)) {
return false;
}
}
} else {
if ( defined( 'WP_REDIS_CLUSTER' ) ) {
Expand Down Expand Up @@ -2147,6 +2167,9 @@ public function set( $key, $value, $group = 'default', $expiration = 0 ) {
$san_group = $this->sanitize_key_part( $group );

$derived_key = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

// Save if group not excluded from redis and redis is up.
if ( ! $this->is_ignored_group( $group ) && $this->redis_status() ) {
Expand Down Expand Up @@ -2257,6 +2280,9 @@ protected function set_multiple_at_once( array $data, $group = 'default', $expir
foreach ( $data as $key => $value ) {
$san_key = $this->sanitize_key_part( $key );
$derived_key = $derived_keys[ $key ] = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

/**
* Filters the cache expiration time
Expand Down Expand Up @@ -2340,6 +2366,9 @@ public function increment( $key, $offset = 1, $group = 'default' ) {
$san_group = $this->sanitize_key_part( $group );

$derived_key = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

// If group is a non-Redis group, save to internal cache, not Redis.
if ( $this->is_ignored_group( $group ) || ! $this->redis_status() ) {
Expand Down Expand Up @@ -2417,6 +2446,9 @@ public function decrement( $key, $offset = 1, $group = 'default' ) {
$san_group = $this->sanitize_key_part( $group );

$derived_key = $this->fast_build_key( $san_key, $san_group );
if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) {
$this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key);
}

// If group is a non-Redis group, save to internal cache, not Redis.
if ( $this->is_ignored_group( $group ) || ! $this->redis_status() ) {
Expand Down