Skip to content

Commit 80104a8

Browse files
committed
Only purge page caches when enabling object cache to preserve session/auth
- Add purge_page_caches() to purge File/Browser caches without flushing object cache - Refactor purge_all() to use purge_page_caches() then flush object cache - When enabling object cache, call purge_page_caches() only to avoid logging out user - When disabling object cache, call purge_all() to clear everything
1 parent 9623f3f commit 80104a8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

includes/Cache/CachePurgingService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ public function manual_purge_request() {
9090
}
9191

9292
/**
93-
* Purge everything.
93+
* Purge page caches only (File, Browser). Does not flush object cache.
94+
* Use when enabling object cache so session/auth data is not flushed.
9495
*/
95-
public function purge_all() {
96+
public function purge_page_caches() {
9697
foreach ( $this->cache_types as $instance ) {
9798
if ( array_key_exists( Purgeable::class, class_implements( $instance ) ) ) {
9899
/**
@@ -103,6 +104,13 @@ public function purge_all() {
103104
$instance->purge_all();
104105
}
105106
}
107+
}
108+
109+
/**
110+
* Purge everything (page caches and object cache).
111+
*/
112+
public function purge_all() {
113+
$this->purge_page_caches();
106114
ObjectCache::flush_object_cache();
107115
}
108116

includes/RestApi/CacheController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ public function update_settings( \WP_REST_Request $request ) {
130130
$out = ObjectCache::disable();
131131
}
132132
if ( $out['success'] ) {
133-
// Purge page cache and object cache (purge_all includes flush_object_cache).
134-
container()->get( 'cachePurger' )->purge_all();
133+
// When enabling: only purge page caches so we don't flush object cache (avoids logging out the user).
134+
// When disabling: purge everything including object cache.
135+
$purger = container()->get( 'cachePurger' );
136+
if ( $enable ) {
137+
$purger->purge_page_caches();
138+
} else {
139+
$purger->purge_all();
140+
}
135141
return new \WP_REST_Response( array( 'result' => true ), 200 );
136142
}
137143
return new \WP_REST_Response(

0 commit comments

Comments
 (0)