Skip to content

Backport: invalidates_query_cache meta parameter#76687

Draft
pkevan wants to merge 2 commits intotrunkfrom
pkevan/backport-wp-dev-11290
Draft

Backport: invalidates_query_cache meta parameter#76687
pkevan wants to merge 2 commits intotrunkfrom
pkevan/backport-wp-dev-11290

Conversation

@pkevan
Copy link
Copy Markdown
Contributor

@pkevan pkevan commented Mar 19, 2026

What?

Backports WordPress Core PR #11290: Allow registering post meta keys that skip query cache invalidation.

Why?

RTC (real-time collaboration) meta keys (wp_sync_awareness, wp_sync_update) are written at high frequency during collaborative editing. Each write was invalidating the posts cache group's last_changed timestamp site-wide, causing all post queries to miss their caches. This backport prevents non-cacheable meta keys from triggering cache invalidation.

How?

Uses hook-based interception since Core's register_meta() cannot be modified:

  • New file: lib/compat/wordpress-7.0/post-meta-cache.php with standalone registry
  • Replaces Core's added/updated/deleted_post_meta hooks with conditional version
  • Registers RTC meta keys as non-cacheable in collaboration.php
  • Automatically disabled when WordPress 7.0+ ships with native support

Testing

  • Verifies that non-cacheable meta writes do not bump wp_cache_get_last_changed( 'posts' )
  • Existing tests should pass unchanged
  • Function is guarded by ! function_exists( 'wp_post_meta_invalidates_query_cache' )

pkevan added 2 commits March 19, 2026 15:47
Prevents RTC meta keys (wp_sync_awareness, wp_sync_update) from invalidating the posts cache group's last_changed timestamp on every write. This avoids cache invalidation storms during high-frequency collaborative editing.

Uses hook-based interception with a standalone registry since Core's register_meta() cannot be modified. When WordPress 7.0 ships with the native implementation, this backport is automatically disabled via function_exists guard.

New file: lib/compat/wordpress-7.0/post-meta-cache.php
- gutenberg_register_non_cacheable_post_meta() to register keys
- wp_post_meta_invalidates_query_cache() public API
- Replaces Core hooks with conditional version that checks registry

Modified: lib/compat/wordpress-7.0/collaboration.php
- Register RTC meta keys as non-cacheable

Modified: lib/load.php
- Load post-meta-cache.php before collaboration.php

See: https://core.trac.wordpress.org/ticket/64696
See: WordPress/wordpress-develop#11290
- Add backport-changelog/7.0/11290.md linking Core PR #11290 to Gutenberg PR #76687
- Suppress unused $post_type parameter warning (kept for API compatibility with Core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant