Skip to content

fix: clear the snippet cache before new state is read back - #572

Merged
TallblokeUK merged 3 commits into
core-betafrom
fix/snippet-cache-invalidation-order/core
Oct 5, 2026
Merged

TallblokeUK merged 3 commits into
core-betafrom
fix/snippet-cache-invalidation-order/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

Fixes #561.

Every write in snippet-ops.php cleared the cached snippet list as its last step, after the new state had already been read back and handed to the write's hooks. Anything reading in between was served the snippet as it stood before the write.

On a site with a persistent object cache this is visible to every user: saving an edited snippet returned the snippet as it was beforehand, and that value is what the REST update response is built from. Activating or deactivating reported the previous status. With file-based execution, the listener on each hook reads the snippet back, so a deactivated snippet was written to disk still marked active and went on running.

The cache is now cleared as soon as the database changes, before the snippet is read back and before any hook fires. Applied across save_snippet(), activate_snippet(), activate_snippets(), deactivate_snippet(), delete_snippet(), trash_snippet() and restore_snippet().

deactivate_snippet() also now passes the network flag when reading the snippet back, which it previously left to default.

Not covered here

The remaining part of the file-based execution report — no fallback to the database when the on-disk index is missing, and no rebuild outside of saving the settings page — is a separate change.

Verification

  • New tests cover the returned value and the hook payload for saving, activating, deactivating and deleting. All seven fail without the change.
  • Snippet creation was checked and is unaffected: a new identifier cannot be present in the cached list, so the read falls through to the database.
  • Full PHPUnit suite (351 tests) and lint:php pass.
  • Driven against a live site for saving, activating and deactivating, confirming the database and the returned snippet now agree.

…into fix/snippet-cache-invalidation-order/core

# Conflicts:
#	CHANGELOG.md
@TallblokeUK
TallblokeUK merged commit a00dc12 into core-beta Oct 5, 2026
18 checks passed
@TallblokeUK
TallblokeUK deleted the fix/snippet-cache-invalidation-order/core branch October 5, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File-based execution keeps running snippets after they are deactivated

1 participant