diff --git a/plugins/cache-on-save/cache-on-save.php b/plugins/cache-on-save/cache-on-save.php index 1fa6f4e..ed5562e 100644 --- a/plugins/cache-on-save/cache-on-save.php +++ b/plugins/cache-on-save/cache-on-save.php @@ -25,6 +25,14 @@ class CacheOnSavePlugin extends Plugin */ private bool $photosReconciled = false; + /** + * Same 4x-per-submit firing as $photosReconciled: onFormProcessed runs once + * per process action. Clearing the page-tree cache is idempotent, but doing it + * four times per post is wasted work (a full deleteAll() + system.yaml touch + * each time). Latch it so the invalidation runs exactly once per submission. + */ + private bool $cacheInvalidated = false; + public static function getSubscribedEvents(): array { return [ @@ -191,16 +199,22 @@ class CacheOnSavePlugin extends Plugin } } - // Two-part invalidation. deleteAll() drops the Doctrine store (the tracker - // feed page cache etc.), but the page-tree INDEX is keyed on + // Two-part invalidation, latched to run ONCE per submit (see + // $cacheInvalidated) — the 4 process actions would otherwise repeat it. + // deleteAll() drops the Doctrine store (the tracker feed page cache etc.), + // but the page-tree INDEX is keyed on // md5(dirs + folderHash + config->checksum() + lang) (Pages::buildRegularPages). // With cache.check.method:folder that index can survive a create — a fresh // entry then stays invisible to the API (GET /api/v1/pages{route} 404s), so // opening the just-posted entry for editing shows "this entry no longer // exists". invalidateCache() touches system.yaml, bumping config->checksum() // so the index key changes and the tree rebuilds on the next request. - $this->grav['cache']->deleteAll(); - Cache::invalidateCache(); + if (!$this->cacheInvalidated) { + $this->cacheInvalidated = true; + $this->grav['cache']->deleteAll(); + Cache::invalidateCache(); + $this->grav['log']->info('cache-on-save: cleared page cache + invalidated page-tree index after new-entry submit'); + } } /**