Immediate cache invalidation for GraphQL persisted queries after Content Fragment publication

This article describes how cache invalidation works for GraphQL persisted queries in Adobe Experience Manager (AEM) 6.5 on-premise and provides guidance for achieving immediate cache invalidation after publishing Content Fragments.

Description description

Environment

  • Adobe Experience Manager (AEM) 6.5 (all service packs, including SP20)
  • On-premise deployment

Issue/Symptoms

  • GraphQL persisted query responses (such as /graphql/execute.json/...) are cached at the Dispatcher layer.
  • When a Content Fragment is updated and published, the corresponding cached GraphQL persisted query response is not invalidated immediately.
  • Users receive stale data from the Dispatcher cache after Content Fragment publication.
  • High request volume can cause increased CPU and resource load on Publisher instances if caching is not effective, potentially leading to server instability and degraded performance.

Cause

AEM 6.5 on-premise does not provide a built-in mechanism to map Content Fragment updates to their dependent GraphQL persisted query cache entries. Dispatcher performs path-based invalidation, so publishing a Content Fragment only invalidates the cache for that specific path (for example, /content/dam/...), not for the GraphQL persisted query response path (for example, /graphql/execute.json/...). As a result, cache invalidation for persisted queries is governed by TTL unless a custom targeted invalidation mechanism is implemented.

Resolution resolution

To fix the cache invalidation issue, follow these steps:

  1. Understand Dispatcher cache invalidation behavior:

    • Dispatcher invalidates cache based on path. By default, publishing a Content Fragment only invalidates the cache for the fragment’s path, not for related GraphQL persisted query responses.
  2. Manage persisted query cache freshness with TTL-based caching:

    • Enable TTL-based caching in Dispatcher by setting enableTTL to 1 in your farm configuration.
    • Ensure that GraphQL responses include appropriate Cache-Control headers (such as max-age or s-maxage).
    • Cached responses will be refreshed after the TTL expires. This approach introduces a delay before new content is visible but requires no custom development.
  3. Implement immediate cache invalidation (custom solution):

    • If immediate invalidation is required, implement a custom cache-flush mechanism that explicitly invalidates the relevant persisted query cache entries when the associated Content Fragment is published.
    • Achieve this by extending the Dispatcher Flush Agent or by creating a custom workflow or process that triggers a targeted cache flush for /graphql/execute.json/... URLs related to the updated Content Fragment.
    • Ensure the custom solution only flushes the necessary cache entries to avoid unnecessary cache invalidation and performance impact.
  4. Verify Dispatcher and Flush Agent configuration:

    • Confirm that the Dispatcher Flush Agent is enabled and functioning.
    • Review the Flush Agent’s configuration to determine which paths are being invalidated on content publication. If only repository paths are invalidated, persisted query cache entries will remain until TTL expiry or manual flush.
  5. Verification:

    • After implementing TTL or a custom invalidation mechanism, publish a Content Fragment and verify that the corresponding GraphQL persisted query response is refreshed in the Dispatcher cache as expected.
recommendation-more-help
experience-cloud-kcs-help-kbarticles