Problem/Motivation

Most of the time, 403/404 pages have a zero Drupal cache max-age (see https://www.drupal.org/node/2920529).
Still, Drupal has a setting named cache_ttl_4xx (defaults to 1 hour) which tells how much time a 403/404 page should stay in Drupal cache (even if Drupal cache max-age is zero).
This module should probably not prevent that behavior, or many 403/404 will remain uncacheable, which is bad for server performance/energy consumption (and many bad bots use to ask for pages that do not exist, looking for security holes).
Furthermore, for even better performance, it would be nice that those pages can remain not only in Drupal cache but also in a reverse-proxy cache (such as Varnish) if there's one.
If you use this module but do not want to cache those error pages, you should simply set cache_ttl_4xx to zero.

Steps to reproduce

Enable the module, ensure your cache_ttl_4xx setting is not zero, go to a non-existing URL (anonymously), you will still get "max-age=0" in the Cache-Control header of the response.

Proposed resolution

Patch coming.

Remaining tasks

Review coming patch.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#6 3364452-allow-40x-caching.patch2.81 KBmichel.g
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

GaëlG created an issue. See original summary.

gaëlg’s picture

Status: Active » Needs review
prudloff’s picture

Status: Needs review » Reviewed & tested by the community

I tried the patch on https://master-oowrqeonft6ldtavsemgri12jdeiaq35.tugboatqa.com/ and confirms it adds a Cache-Control: max-age=3600, public header on 404 pages.

I also tested locally that setting $settings['cache_ttl_4xx'] changes the duration.

prudloff’s picture

Issue tags: +DrupalCon Lille 2023
michel.g’s picture

StatusFileSize
new2.81 KB

Got merge conflicts with the latest dev branch so I've created a new patch (no access to alter the MR)

gaëlg’s picture

I think you should have a "get push access" green button above, to alter the MR.

prudloff changed the visibility of the branch 2.0.x to hidden.

prudloff changed the visibility of the branch 3364452+3350593 to hidden.

prudloff changed the visibility of the branch 3364452+3350593+2910705 to hidden.