When an existing DAM asset is updated via AssetFileEntityHelper::updateExistingFile(), the binary data on the filesystem is replaced, but the filename and URI remain the same. While the module correctly flushes image derivatives and invalidates internal Drupal cache tags, external caching layers—such as Varnish, CDNs, and Browsers—continue to serve the old version of the file because the URL hasn't changed.

To resolve this, we need to implement a cache-busting mechanism that appends a changed query string (the file's changed timestamp) to the generated file URLs.

Problem/Motivation

Currently, users must wait for external caches to expire or perform manual purges to see updated assets. By appending ?changed=[timestamp] to the URL, we ensure that every time an asset is replaced in Drupal, the URL becomes unique to external caches, forcing them to fetch the fresh content immediately.

Steps to reproduce

Proposed resolution

  • Service Decoration: Decorate the file_url_generator service to intercept URL generation for files stored in the DAM directory (public://dam/).
  • Versioning Logic: Implement generateString() to append ?changed=[changed_timestamp] to the URL string.
    • Implement generate() to add the same timestamp to the $options['query'] array of the Url object.
  • Performance Optimization: Use a static cache within the decorator to store timestamps, preventing redundant database lookups during a single request load.

Issue fork acquia_dam-3588200

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajeshreeputra created an issue. See original summary.

rajeshreeputra’s picture

Assigned: Unassigned » rajeshreeputra
Status: Active » Needs review

Created MR, requesting review. Code coverage will be added later.

rajeshreeputra’s picture

Updated existing test to include code coverage for ?changed=[timestamp] in file DAM asset's local file url.
Requesting review.

rohan-sinha’s picture

Status: Needs review » Reviewed & tested by the community

Tested the MR, all looks good.

rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

MR merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.