Time-based custom caching is broken since configuration expects an integer.

Created on 15 September 2021, about 3 years ago
Updated 20 September 2024, about 2 months ago

Problem/Motivation

In Drupal 8 and 9, some weird behaviour happens in Views Time-based cache.

The problem only occurs when using Time-based "Custom" time.

Problem 1:
Configuration results_lifespan and output_lifespan are never saved as 'custom'.
It is saved as 0, even if we choose 'Custom'.

Problem 2: (php8 only)
in getLifespan, we have this one liner
$lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];

Since $this->options[$type . '_lifespan'] is never 'custom' but 0 instead (problem 1),
it is like:
0 == 'custom'

Now in php7, this returns TRUE.
But in php8, this returns FALSE, so when views_ui loads the views, custom time-based cache will always show '0sec, 0sec'.

Why this happens

When building options (buildOptionsForm), there is some formatted [60, 300, 1800, 3600, 21600, 518400] options as $options
and then
$options = [0 => $this->t('Never cache')] + $options + ['custom' => $this->t('Custom')];

But views.cache.schema.yml type for both results_lifespan and output_lifespan is integer

Steps to reproduce

Edit a view
Set Caching as Time-based with Custom value
Save the view
Check Caching value again

Proposed resolution

Use number 7 as option key for 'Custom' time-based cache.

Remaining tasks

Reviews and input from community.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated about 4 hours ago

Created by

🇨🇦Canada simgui8 Canada

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

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