Skip to content

Commit 6fa46fa

Browse files
committed
Invent cache salt
If there are multiple sites using the same redis server then invent a salt that gives uniqueness for each site to avoid collision. Signed-off-by: ed neville <[email protected]>
1 parent d4f76c2 commit 6fa46fa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

includes/object-cache.php

+8
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ function wp_cache_init() {
249249
define( 'WP_REDIS_PREFIX', getenv( 'HTTP_X_APP_USER' ) );
250250
}
251251

252+
// If `WP_REDIS_PREFIX` is not set, relate to the DB connection
253+
if ( ! defined( 'WP_REDIS_PREFIX' ) ) {
254+
if ( defined( 'DB_NAME' ) && defined( 'DB_USER' ) && defined( 'DB_PASSWORD' ) && defined( 'DB_HOST' ) ) {
255+
global $blog_id, $table_prefix;
256+
define( 'WP_REDIS_PREFIX', md5( DB_NAME . ":" . DB_USER . ":" . DB_PASSWORD . ":" . DB_HOST . ":" . $table_prefix . ":" . $blog_id ) );
257+
}
258+
}
259+
252260
if ( ! ( $wp_object_cache instanceof WP_Object_Cache ) ) {
253261
$fail_gracefully = defined( 'WP_REDIS_GRACEFUL' ) && WP_REDIS_GRACEFUL;
254262

0 commit comments

Comments
 (0)