Skip to content

Use prefixed Redis keys to prevent data loss on cache clearing. #324

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sdellenb
Copy link

@sdellenb sdellenb commented Mar 8, 2025

Only cachify entries that belong to the current host are removed from the cache.

Now only the entries that belong to the current host are removed from the cache.
@self::$_redis->flushAll();
/* Delete all cache entries for this site */
$host = wp_unslash( $_SERVER['HTTP_HOST'] );
$keys = self::$_redis->keys( $host . '*' );
Copy link
Author

@sdellenb sdellenb Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keys() returns the keys with the configured prefix, but del() or unlink() do not expect it and will add it again before sending the command to Redis.

This quirk of phpredis was discussed in phpredis/phpredis#1117 (comment) and only has to be considered when bulk-deleting.

Copy the phpcs:ignore from `_file_path()` and split the multi-line function arguments properly.
Copy link

sonarqubecloud bot commented Mar 9, 2025

@stklcode stklcode added this to the 2.5.0 milestone Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants