Problem/Motivation
Some things are not ever cacheable (e.g. if they depend on data that is stored externally and that can be changed any second). In that case, they should return max-age = 0. Consequently, cache tags and cache contexts do not matter anymore: the thing is not cacheable at all anyway.
Implementing all three methods of CacheableDependencyInterface in these cases is a chore.
Proposed resolution
Provide an UncacheableDependencyTrait, just like we provide its opposite already: UnchangingCacheableDependencyTrait.
Remaining tasks
Review.
User interface changes
None.
API changes
None, just adding a new trait.
Data model changes
None.
Comments
Comment #2
wim leersRealized this while working on #2624472: Make sure that cache tags of index and server are added to search result pages.
Comment #3
wim leersComment #4
wim leersComment #5
fabianx commentedRTBC - a nice helper
Comment #6
tstoecklerSeems this should be 8.1.x right?
Comment #7
wim leersCore classes that could be updated to use this:
\Drupal\early_rendering_controller_test\CacheableTestDomainObject\Drupal\history\Plugin\views\filter\HistoryUserTimestamp\Drupal\views\Plugin\views\sort\Random(Perhaps more, this is what a quick search turned up.)
Comment #8
alexpottI think we should put this 8.1.x since it is not a bug and at least have those classes use it.
Comment #9
wim leersAgreed.
Comment #10
alexpottThis means we're going to override the implementation of FilterPluginBase::getCacheContexts() - do we not care about cache contexts if the max age is 0?
Comment #11
wim leersNot in this case, because the max-age is unconditionally zero. If it were conditional, then we'd need/want the cache contexts.
Hence this bit of documentation. I could make that more explicit.
Comment #12
borisson_Added the extra documentation Wim mentioned in #11.
Comment #13
wim leersThanks @borisson_, that looks great :)
Comment #15
fabianx commentedBack to RTBC for 8.x-2.x
Comment #17
catchCommitted/pushed to 8.2.x, thanks!
Comment #18
wim leersUpdated documentation: https://www.drupal.org/node/2541914/revisions/view/9158196/9566219.
Comment #19
jibranQuick follow up patch.
Comment #20
wim leersOh, hah! YAY!
RTBC++
Comment #22
catchDoh. Committed/pushed to 8.2.x, thanks!