Source file redirects get cached indefinitely

Created on 15 October 2024, about 1 month ago

Problem/Motivation

Redirects to source file get cached indefinitely and if you change the source file you need to do a cache rebuild in order for the media canonical link to redirect you to the new file.

Steps to reproduce

1. Install Media link enhancements and enable redirects.
2. Instal a media file replace contrib module (media_entity_file_replace for example).
3. Create a new file media (file1.txt) and access the canonical url. This will redirect you to sites/default/files/2024/10/file1.txt.
4. Replace the file file1.txt with file2.txt.

Expected result:
The media canonical url will redirect you to the new file: sites/default/files/2024/10/file2.txt.
Actual result:
The media canonical url redirects to the old file: sites/default/files/2024/10/file1.txt.

Proposed resolution

The MediaLinkEnhancementsController uses a TrustedRedirectResponse which extends CacheableSecuredRedirectResponse and does not set any cache contexts or cache tags.
Setting the url.site cache context and the media:[id] cache tag ensures that the redirect is updated when the media is updated.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇷🇴Romania bogdan.dinu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024