The Sidewide Alerts load route set a maximum cache max age of 30 in an interesting spot

Created on 25 September 2024, 3 months ago

Problem/Motivation

In Drupal\sitewide_alert\Controller\SitewideAlertsController::load(), ~ line 104, we see the following code:

  // Set response cache so it's invalidated whenever alerts get updated, or
  // settings are changed.
  $cacheableMetadata = (new CacheableMetadata())
    ->setCacheMaxAge(30)
    ->addCacheContexts(['languages'])
    ->setCacheTags(['sitewide_alert_list']);
  $cacheableMetadata->addCacheableDependency($sitewideAlertSettings);

I'm not sure why we set the cache max age to 30 seconds here. I don't think we should be, especially given the comment above noting that we are just setting making sure alerts are only cached until an alert is created/updated or the module's settings are altered.

I only noticed this because I installed the Cache Control Override β†’ module and, for a reason TBD, with that module enabled, the load route always returns a max age of 30. This is interesting behavior. But I noticed that after removing this line setting max age to 30s, the cache max age of the load response is the expected, module configured value, whether I have Cache Control Override installed or not.

Steps to reproduce

Proposed resolution

Don't set the Cache Max Age to 30 here. I do not believe there is a reason to do so.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States sonfd Portland, ME

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024