Is there some sort of object cache server, like Redis, that can be easily integrated with Local.app?
I find myself needing to test object cache data and return locally.
I find myself needing to test object cache data and return locally.
Hey @afragen! As far as I know there isnât anything that can be integrated, at least not easily.
We do have a feature request hanging around too:
Thanks @Nick-B
Just like the feature request you referenced, Iâd like to be able to test locally using an object cache.
Iâve reached out to our Dev team @afragen to see if they have any other thoughts or recommendations on this!
I might have found a solution. Docket Cache â Object Cache Accelerator â WordPress plugin | WordPress.org
Testing.
@afragen Local doesnât offer an âeasy integrationâ at the moment, but hereâs a guide to configure redis as an object cache with Local. (Assumes macOS.)
Steps 1 and 2 are one-time only. Steps 3 onward are needed per-site.
brew install redis
No Docker needed, weâll just use the native binary.
brew services start redis
This will start redis-server now, and automatically restart it if you reboot.
brew services stop redis to stop it.
wp-config.phpBe sure to change WP_REDIS_DATABASE or WP_REDIS_PREFIX (one or the other is fine) if using the same redis instance with multiple sites.
define('WP_REDIS_CLIENT', 'predis'); // Use PHP client, Local does not bundle the native PhpRedis extension.
define('WP_REDIS_HOST', '127.0.0.1'); // Assumes redis-server is running.
define('WP_REDIS_PORT', 6379); // Default port is fine for us running redis-server.
define('WP_REDIS_DATABASE', 0); // Either pick a unique DB per site, 0-15, orâŚ
define('WP_REDIS_PREFIX', 'mysite:'); // âŚalternatively pick a unique prefix per site.
wp plugin install redis-cache --activate
wp redis enable
You should see âSuccess: Object cache enabled.â
Thatâs it, youâre done!
You can do wp redis status for more info for each site.
In your WP Admin, you should see this under Settings â Redis:
Either:
wp redis disable via CLI in the site shellPredis is slower than PHPâs native PhpRedis extension, but should be fine for testing.
Itâs likely possible to wrap this setup in an add-on to reduce manual steps and enable/disable Redis per-site via Localâs UI. But there will be gotchas like managing site prefixes and databases, configuring/tuning Redis, and ensuring cross-platform support.
Thanks @nickc! This is awesome, truly above and beyond. Now if someone there wants to create an Add-On⌠![]()
Also, add to wp-config.php, need unique
define( 'WP_CACHE_KEY_SALT', 'example' );
define( 'WP_REDIS_SELECTIVE_FLUSH', true);
with âexampleâ a random string from https://api.wordpress.org/secret-key/1.1/salt/ for each site.
This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.