Cache tag invalidation skipped due to failed database transaction
0 reputation · 27 Aug 2020, 08:49 UTC
0 reputation · 27 Aug 2020, 08:49 UTC
The goal is to guarantee that authenticated users always receive up‑to‑date dynamic page cache content without requiring site builders to manually add the 'user' cache context.
This raises constraints around potential performance overhead, backward compatibility for existing sites that rely on custom cache contexts, and the pending core decision about whether such enforcement should be automatic.
Because the core has not yet decided to enforce automatic cache context variation for authenticated users when using dynamic page caches, it remains unclear whether the benefit of guaranteed freshness outweighs the possible impact on cache hit rates and resource consumption.
Should Drupal core automatically apply the 'user' cache context to dynamic page cache for authenticated users?
What performance trade‑offs would arise from enforcing this context variation on high‑traffic sites?
How would this change affect existing implementations that already manage cache contexts customly?
35275 reputation · 27 Aug 2020, 12:49 UTC
Drupal core should not automatically apply the user cache context to the dynamic page cache for all authenticated users. Doing so would prioritize absolute data freshness at the cost of fundamentally breaking the efficiency of the caching layer.
In Drupal's cache API, contexts determine variation (who sees what), while tags determine invalidation (when to clear). If a page displays user-specific data but fails to declare the user context, it is a bug in the content's cacheability metadata, not a failure of the cache system.
user context creates a unique cache entry for every single authenticated user. On a site with 10,000 active users, a single page that could have been shared across all users (or groups of users) now requires 10,000 separate entries.For sites already managing cache contexts customly, automatic enforcement would not overwrite their specific logic—since contexts are merged—but it would render their optimizations moot. If a developer specifically used user.roles to allow all "Editors" to share a cache entry, a forced user context would override this efficiency, forcing per-user variation regardless of role similarity.
Rather than a blanket enforcement, the following strategies maintain both correctness and performance:
user.roles or user.permissions when content varies by group rather than individual.#lazy_builder callbacks for highly dynamic, user-specific fragments. This allows the rest of the page to remain cached globally while only the user-specific part is rendered dynamically.user cache context.Diagnostic Note: To provide a more specific recommendation for your environment, please clarify if you are seeing "leaked" content (User A seeing User B's data) or if this is a theoretical architectural concern.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.