Invalidate cached responses when new redirects are added

Created on 21 May 2025, 3 months ago

Problem/Motivation

When a redirect is detected, the redirect entity is added to the response as a cacheable dependency. The response then may be cache by, for example, Dynamic Page Cache. When that redirect is changed or deleted, the response is invalidated by the entity cache tags of the redirect.

However, because of the possibility of having redirect chains, a new redirect that affects the response may be created but the response may still be served from the cache - sending the user to the wrong page.

Steps to reproduce

Proposed resolution

Add the redirect_list cache tag to redirection responses, or analyze the cases and, for example, load redirects that could be affected by adding a new one in their chain and invalidate the entity cache tags for those redirects.

Remaining tasks

Ideally, implement the more accurate solution.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡ͺPeru krystalcode

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

Merge Requests

Comments & Activities

  • Issue created by @krystalcode
  • πŸ‡΅πŸ‡ͺPeru krystalcode

    Implementing the quick - but less efficient - solution for now.

  • Status changed to Needs work 18 days ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Interesting bug and yeah clearing all redirects out of the cache when generating or deleting redirects does feel sub-optimal. I feel that to fix this bug properly we should be adding test coverage to ensure we've got the bug and any edge cases we can imagine covered. Also adding test coverage will make it easier to move to a better solution.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Going to see if I can write a failing test.

  • Merge request !153Add a test β†’ (Merged) created by alexpott
  • Pipeline finished with Failed
    18 days ago
    Total: 181s
    #569986
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've found the bug here. It's because we're not adding all the redirects involved when processing a redirect chain - we're only adding the last one. Therefore when we update another redirect in the chain the cache is not correctly invalidated. Adding all the redirects in makes the system work as expected.

  • Pipeline finished with Failed
    18 days ago
    Total: 190s
    #569994
  • Pipeline finished with Failed
    18 days ago
    Total: 334s
    #570039
  • Pipeline finished with Success
    18 days ago
    Total: 184s
    #570092
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Added a comment on the phpstan thing we discussed.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Thanks @berdir

  • Pipeline finished with Failed
    17 days ago
    Total: 304s
    #571464
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    actually fails on cspell now.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @berdir yay! No regressions :)

  • Pipeline finished with Success
    16 days ago
    Total: 160s
    #571873
  • Pipeline finished with Skipped
    16 days ago
    #571910
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Yes, point for you in that argument I guess ;)

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024