Trigger a deprecation when using \Drupal\Core\Cache\RefinableCacheableDependencyTrait::addCacheableDependency with a non CacheableDependencyInterface object

Created on 9 September 2021, over 3 years ago
Updated 13 May 2024, 8 months ago

Problem/Motivation

If you call \Drupal\Core\Cache\RefinableCacheableDependencyTrait::addCacheableDependency with something that doesn't implement CacheableDependencyInterface, you end up with uncacheable pages.

Examples of bugs in core this has lead to include: 🐛 NodeController::revisionOverview is uncacheable Needs review and probably more.

I would argue that we should move towards deprecating calling this method with an object that doesn't implement CacheableDependencyInterface to prevent people from inadvertently introducing non-cacheable pages.

Steps to reproduce

Call \Drupal\Core\Cache\RefinableCacheableDependencyTrait::addCacheableDependency with \Drupal::currentUser or a render array - see your page becomes uncacheable

Proposed resolution

Trigger a deprecation error if called with an object that doesn't implement CacheableDependencyInterface
In the next major version remove that deprecation error and add a type-hint (hard break).

Remaining tasks

All of the above

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Cache 

Last updated 5 days ago

Created by

🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024