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_generatorservice 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 theUrlobject. - 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
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
Comment #3
rajeshreeputraCreated MR, requesting review. Code coverage will be added later.
Comment #4
rajeshreeputraUpdated existing test to include code coverage for
?changed=[timestamp]in file DAM asset's local file url.Requesting review.
Comment #5
rohan-sinha commentedTested the MR, all looks good.
Comment #7
rajeshreeputraMR merged!