Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
FileEntity::getCacheTags returns an empty array. This breaks the cache invalidation for File entities in Views for example.
IRC log
<webflo> berdir: http://cgit.drupalcode.org/file_entity/tree/src/Entity/FileEntity.php#n500 i think FileEntity:: getCacheTags returns no cache tag. i think this breaks tag-based cache invalidation in views.
<webflo> i use field based rendering in views, no rendered entity
<berdir> webflo: hm, yes, that is possible...
<berdir> webflo: tricky. that optimization is quite important for us/anyone who has lots and lots of files on overview pages. maybe we could make it configurable? but then you still have to know that you have to change that settings
<berdir> webflo: maybe we can somehow apply the logic from \Drupal\file_entity\Entity\FileEntityViewBuilder to it?
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#19 | cache_tags_invalidation-2831156-19.patch | 4.63 KB | vflirt |
#16 | 2831156-16.patch | 4.78 KB | webflo |
#10 | 2831156-10.patch | 4.62 KB | webflo |
#8 | 2831156-8.patch | 4.56 KB | webflo |
#7 | 2831156-7.patch | 4.59 KB | webflo |
Comments
Comment #2
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #3
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #4
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #5
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #6
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #7
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedThis change has was introduced in fbf9a5a. I don't understands whats the reason behind the change. Is it related to cache invalidation for embedded files (in text fields)? Lets see hat happens if we remove that optimization. It should pass from what i understand.
Comment #8
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #9
BerdirHm, didn't we discuss why this was done at some point? Or was that with someone else?
Basically, the causes an explosion of cache tags if you have a lot of files on your nodes, this saves us dozens of cache tags on frontpages that almost never change.
Can explain the views use case a bit more? I can see how that could be a problem in some scenarios, but maybe we can find a better solution for that, basically the same as the fix in the view builder basically?
Comment #10
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #11
joseph.olstadComment #12
BerdirThis was actually set to active on purpose, discussed that with @webflo as he's just rerolling this for this project that needs this for nw.
But I'm closing it now as works as designed unless someone can convince me otherwise :)
Comment #13
joseph.olstadOk, thanks for the explanation.
Comment #14
zviryatko CreditAttribution: zviryatko as a volunteer and commented@berdir it also breaks the JSON API module, since individual resource (File entity) still accessible without cache tags and once you update file data cache not updated automatically.
Comment #15
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedAnother update.
@zviryatko Whats your workaround for JSON API module? Maybe we can find a common solution ...
Comment #16
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #17
BerdirLets reopen for now. Maybe we can make it a setting, document that the current mode is better for performance as it avoids possibly a ton of extra cache tags but some use cases like decoupled might not work?
Comment #18
zviryatko CreditAttribution: zviryatko as a volunteer and commented@webflo, I've used this patch for fixing jsonapi cache issues, but file_entity requires few other changes to work with jsonapi and jsonapi_extras.
Comment #19
vflirt CreditAttribution: vflirt commentedI have stumbuled on this issue as we have some code that does not properly populate the file_usage table which results in cache not being cleared. I am updating the patch for latest dev.