Introduce constants for #cache keys

Created on 2 June 2020, over 4 years ago
Updated 7 October 2024, 4 months ago

Problem/Motivation

Today I had some problems because I wrote context instead of contexts inside #cache. There is no error message and really no way to know this is wrong. It just doesn't work. While similar could be said of the render keys themselves, the truth is it's easy to search for those, the @FormElement plugin doxygen typically lists them and so forth. But searching for context in D8 is just futile.

Proposed resolution

Introduce constants. It's easy and painless.

Remaining tasks

If we want to switch over every usage that'll be a bear and not the teddy kind. I haven't done so.

User interface changes

None

API changes

New constants are available in core/lib/Drupal/Core/Cache/Cache:

const CONTEXTS = 'contexts';
const TAGS = 'tags';
const MAX_AGE = 'max-age';

Data model changes

None.

Release notes snippet

New constants have been added to make writing #cache arrays easier: Cache::CONTEXTS, Cache::TAGS and Cache::MAX_AGE,

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
CacheΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

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