Thread Starter
webmdt
(@webmdt)
Update: After properly purging the Cache from Redis, I can clearly see that the plugin is not using the “DB ID” at all. It instead defaults to write ALL cache to the “DB 1”.
Running a Select Query within REDIS-CLI, I can see all of the cache pooling into DB 1.
I have fixed the NAMESPACING issue when running multiple WordPress Installs on the same sub-domain,
Cache_Base.php LINE 180 (add the new function “getSiteInfo” and modify the “*key*” functions)
/**
* Grabs the DB Name
*
*/
public function getSiteInfo(){
/*Grab the RAW DB from the WP Config*/
$rawDB = DB_NAME;
/*Force the info to be lowercase*/
$siteInfo = strtolower($rawDB);
/*If an underscore exists .. only output everything AFTER it*/
if (($underscoreCheck = strpos($rawDB, "_")) !== FALSE) {
$siteInfo = substr($siteInfo, $underscoreCheck + 1);
}
return $siteInfo;
}
/**
* Constructs key version key
*
* @param unknown $group
* @return string
*/
protected function _get_key_version_key( $group = '' ) {
return sprintf( 'w3tc_%s_%d_%s_%s_%d_key_version', $this->getSiteInfo(), $this->_blog_id, $this->_module, $group, $this->_instance_id );
}
/**
* Constructs item key
*
* @param unknown $name
* @return string
*/
public function get_item_key( $name ) {
$key = sprintf( 'w3tc_%s_%s_%d_%s_%s', $this->getSiteInfo(), $this->_host, $this->_blog_id, $this->_module, $name );
return $key;
}
Note: This fix works by taking the Table DB Name, and using it to modify the key name. You can modify this function as you see fit
Hey @webmdt,
Nice catch on the Redis DB issue.
I see that you have found a workaround that works for you.
If you’re still interested in how to make W3TC use the correct Redis DB, here’s the patch: https://github.com/charlesLF/fix-w3tc/commit/c35f7815d173489655835bf2f6f4bf3a777e0628
Cheers
Thread Starter
webmdt
(@webmdt)
Hello Charles,
Wow this is very helpful. My FIX doesn’t solve the DB ID issue, it merely just namespaces the KEYS to ensure there isn’t any collisions between the WordPress Builds.
This fix looks great, I’ll apply this on my next deployment.
Thanks
I think I will use your patch (or a variation of it) for the key namespacing on my local installs. This is indeed helpful for the cases where different WP installs reside on different subfolders of the same domain.
I’ll push it to the same repo branch when done, so you might want to keep an eye 🙂