Skip to content

Static cache invalidation strips trailing slashes from rules #14701

@jackmcdade

Description

@jackmcdade

Bug description

When trailing slashes are enforced (URL::enforceTrailingSlashes()), custom invalidation rules with trailing slashes don't clear the cache.

Example config:

'collections' => [
    'events' => [
        'urls' => [
            '/events/',
            '/annual-meeting/',
        ],
    ],
],

It seems DefaultInvalidator tidies relative rules with withTrailingSlash: false, so /events/ becomes /events. Invalidation then does an exact match against the URL index, which stores the request path (e.g. /events/).

Relevant code:

// src/StaticCaching/DefaultInvalidator.php
->map(fn (string $rule) => URL::tidy($entry->site()->url().'/'.$rule, withTrailingSlash: false))

Note: DefaultUrlExcluder already normalizes via URL::tidy() on both sides, so exclusions handle this correctly — invalidation probably should too.

How to reproduce

  1. Enable trailing slashes
  2. Enable static caching
  3. Add invalidation rules like above for a collection
  4. Cache pages that use those URLs (e.g. pages with a collection tag pulling event data)
  5. Edit an entry in the events collection
  6. Cached pages at /events/ and /annual-meeting/ are not invalidated

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions