Skip to content

Commit 559d915

Browse files
committed
Object cache (Redis drop-in): enable/disable, UI, and purge behavior
- ObjectCache: detect drop-in, enable/disable, restore on activation, flush - Only show Object Cache block when Redis constants available (no toggle when unavailable) - Preference option (1/true/null) respected; restore drop-in when preference on but file missing - enable() returns error when Redis not configured; no download attempted - Disable: flush + clear options cache (active_plugins, alloptions), shutdown flush so Redis stays empty - purge_all (nfd_purge_all=1) and CacheController purge_all now flush object cache - Lifecycle: maybe_restore_on_activation, maybe_remove_dropin_if_unavailable, clear_options_object_cache - REST get_settings and runtime call maybe_restore_dropin so UI state matches preference - Add credis to composer for drop-in compatibility - UI: Object Cache section with toggle; sync with store on cache level change
1 parent ef4395b commit 559d915

File tree

19 files changed

+718
-35
lines changed

19 files changed

+718
-35
lines changed

build/performance/performance-rtl.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/performance/performance.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '2244fe1f30f2c155ac60');
1+
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '14cf446de2a270de47ee');

build/performance/performance.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/performance/performance.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333
},
3434
"require": {
35+
"colinmollenhour/credis": "^1.14",
3536
"newfold-labs/wp-module-context": "^1.0",
3637
"wp-forge/collection": "^1.0",
3738
"wp-forge/wp-htaccess-manager": "^1.0",

composer.lock

Lines changed: 48 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/Cache/Cache.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use NewfoldLabs\WP\ModuleLoader\Container;
66

7+
use NewfoldLabs\WP\Module\Performance\Cache\Types\ObjectCache;
8+
79
use function NewfoldLabs\WP\Module\Performance\get_cache_exclusion;
810
use function NewfoldLabs\WP\Module\Performance\get_cache_level;
911

@@ -73,10 +75,12 @@ public function on_cache_level_change() {
7375
* @return array SDK data.
7476
*/
7577
public function add_to_runtime( $sdk ) {
76-
78+
// If preference is "on" but the drop-in is missing, restore so runtime has correct enabled state.
79+
ObjectCache::maybe_restore_dropin();
7780
$values = array(
78-
'level' => get_cache_level(),
79-
'exclusion' => get_cache_exclusion(),
81+
'level' => get_cache_level(),
82+
'exclusion' => get_cache_exclusion(),
83+
'objectCache' => ObjectCache::get_state(),
8084
);
8185

8286
return array_merge( $sdk, array( 'cache' => $values ) );

includes/Cache/CachePurgingService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use NewfoldLabs\WP\Module\Performance\Performance;
66
use NewfoldLabs\WP\Module\Performance\Cache\Types\CacheBase;
7+
use NewfoldLabs\WP\Module\Performance\Cache\Types\ObjectCache;
78
use wpscholar\Url;
89

910
use function NewfoldLabs\WP\Module\Performance\to_studly_case;
@@ -102,6 +103,7 @@ public function purge_all() {
102103
$instance->purge_all();
103104
}
104105
}
106+
ObjectCache::flush_object_cache();
105107
}
106108

107109
/**

0 commit comments

Comments
 (0)