Problem/Motivation
Cache metadata on file entities, that have been uploaded through the text editor, are not bubbling up to the containing node.
I came across this issue whilst working on #2772847: Add support for private uploads / presigned URLs. Our S3 image urls have a signature that expires after a certain amount of time, so we are setting a max-age on the file entity. This however is not working for images uploaded through the texteditor, resulting in expired url signatures and 403s on images.
Steps to reproduce
1) Enable image uploads in one of your text editor settings.
2) Set a max-age on the file entity of 60 seconds (do some logic that changes every 60 minutes, such as dynamically changing url parameters).
3) View the rendered node with render caching enabled
4) Wait 60 seconds
Expected result:
The cache for the file entity + node should regenerate
Actual result:
The previous cache is used.
Proposed resolution
Set the file as a cacheable dependency of the render array.
Remaining tasks
- Fix this in code.
- Write tests
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3228329-drupal-core-files-uploaded-through-text-editor-cache-dependency-2.patch | 648 bytes | leon kessler |
Comments
Comment #2
leon kessler commentedMight be as simple a change as this.
I do wonder why it wasn't already set like this though?
I had a quick look at writing tests, there is already some basic tests for cache tags in EditorFileReferenceFilterTest, however I was unable to set a max-age through this test. So may have to use a test module to do this (through hook_file_load()).
Comment #3
cilefen commentedgit blame
Comment #4
leon kessler commentedI did look at git blame. The code is pretty old, from 2014.
https://git.drupalcode.org/project/drupal/-/blame/9.2.x/core/modules/edi...
I do wonder if the cache system was much more limited back then.
Comment #5
cilefen commentedIt actually looks like you have to look further back in time because that commit was a response to a method rename. But, yes, this is reaching pre Drupal 8 launch era.
Comment #10
wim leersThis bug is still relevant.
The thing is though that
Fileentities in Drupal core have no cache contexts or max-age specified, which is why this went unnoticed.