Skip to content

Add optional Statamic static-cache invalidation integration for targeted Cloudflare purges#6

Merged
eminos merged 3 commits intomainfrom
copilot/support-static-cache-configuration
Feb 20, 2026
Merged

Add optional Statamic static-cache invalidation integration for targeted Cloudflare purges#6
eminos merged 3 commits intomainfrom
copilot/support-static-cache-configuration

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

The addon currently purges Cloudflare on direct content events, which can be overly broad for sites already using Statamic static cache invalidation rules. This change adds an opt-in mode to consume Statamic invalidation events so Cloudflare purges can follow static_caching.invalidation behavior.

  • New opt-in invalidation mode

    • Added cloudflare-cache.use_statamic_static_cache_invalidation (env: CLOUDFLARE_CACHE_USE_STATAMIC_STATIC_CACHE_INVALIDATION, default false).
    • When enabled, the listener handles only Statamic static-cache invalidation events and ignores legacy content events.
    • Default behavior remains unchanged for backward compatibility.
  • Event wiring for Statamic invalidation flow

    • Subscribed the addon listener to:
      • Statamic\Events\UrlInvalidated
      • Statamic\Events\StaticCacheCleared
    • Added corresponding purge_on toggles:
      • url_invalidated
      • static_cache_cleared
  • Listener behavior changes

    • UrlInvalidated now maps to URL-based Cloudflare purge.
    • StaticCacheCleared follows existing fallback semantics (purge everything when configured).
    • Legacy event handling path is preserved and gated by the new mode flag.
  • Docs and examples

    • Updated README/config examples to include the new mode and purge_on keys.
    • Added explicit inline comments and README guidance clarifying this is an either/or mode:
      • default mode = addon legacy content events
      • static cache mode = Statamic static cache invalidation events only
  • Debug logging for misconfiguration/mode mismatch

    • Added debug logs (when cloudflare-cache.debug is enabled) for skipped events and why they were skipped, including:
      • addon disabled
      • mode mismatch (legacy event in static-cache mode, or vice versa)
      • missing event mapping
      • disabled purge_on key
  • Focused test coverage

    • Added listener tests for:
      • legacy events ignored when static-cache mode is enabled
      • URL purge on UrlInvalidated
      • full purge on StaticCacheCleared (fallback enabled)
      • no purge on StaticCacheCleared (fallback disabled)
      • debug logging in mode mismatch/misconfiguration scenarios
// config/cloudflare-cache.php
return [
    // When enabled, only Statamic Static Cache events are handled (UrlInvalidated/StaticCacheCleared).
    // Legacy addon content events are skipped in this mode.
    'use_statamic_static_cache_invalidation' => env(
        'CLOUDFLARE_CACHE_USE_STATAMIC_STATIC_CACHE_INVALIDATION',
        false
    ),

    'purge_on' => [
        // ...
        'url_invalidated' => true, // Statamic Static Cache: UrlInvalidated event
        'static_cache_cleared' => true, // Statamic Static Cache: StaticCacheCleared event
    ],
];

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<issue_title>Support static_cache.php configuration</issue_title>
<issue_description>Nice addon! I was wondering if there are any plans to support the "invalidation" configurations from config/statamic/static_cache.php.

For example, I may want to purge both my homepage and an entry once an entry is saved/updated.</issue_description>

<agent_instructions>- Make it configurable.

  • Check if there are any Statamic events we can hook into, and bypass reading the static_cache.php config ourselves.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@eminos That makes sense and is a great idea. As for now the whole Cloudflare Cache is purged on any type of content update, which is a bit "extreme" (but works fine!). I think this addon could have a lot of nice features added to it. I'll look into this once I get some time over, but also anyone can feel free to contribute! Let's create the best Cloudflare Cache addon for Statamic 🙂

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: eminos <1682784+eminos@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for static_cache.php configuration Add optional Statamic static-cache invalidation integration for targeted Cloudflare purges Feb 20, 2026
Copilot AI requested a review from eminos February 20, 2026 09:26
'nav_tree_saved' => true,
'global_set_saved' => true,
'global_set_deleted' => true,
'url_invalidated' => true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an inline comment to these to say they are Statamic Static Cache related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added inline comments in config/cloudflare-cache.php for purge_on.url_invalidated and purge_on.static_cache_cleared to clearly mark them as Statamic Static Cache related. Addressed in commit 5d80754.

'static_cache_cleared' => true,
],

'use_statamic_static_cache_invalidation' => env('CLOUDFLARE_CACHE_USE_STATAMIC_STATIC_CACHE_INVALIDATION', false),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does enabling this disable our own event handling? In that case it should be made clear with a comment of how it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — enabling use_statamic_static_cache_invalidation switches to Statamic Static Cache events only. I added explicit inline config comments and README wording to make the either/or behavior clear. Addressed in commit 5d80754.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be clear of how it works. Our own event handling + the new Statamic Static Cache events. We're not using both simultaneously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it is either/or. I clarified this in both config comments and README under an "Event handling modes (either/or)" section. Addressed in commit 5d80754.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the debug logging to show if and why something is mis-configured.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added debug logs for skipped events and mode mismatches (including disabled addon, mode mismatch, missing mapping, and disabled purge_on keys) to help diagnose misconfiguration. Addressed in commit 5d80754.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure we have test covering any mis-configurations as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added focused listener tests for misconfiguration paths, including logging when events are skipped due to mode mismatch. Addressed in commit 5d80754.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log if there is any mis-configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented debug logging for misconfiguration-related skips in the listener so misconfiguration is visible when cloudflare-cache.debug is enabled. Addressed in commit 5d80754.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the readme to explain how our own event tracking work in conjunction with the Statamic Static Cache events. It's either or, right? Let's make that clear. Add the same comments as in the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated README to match config comments and clearly explain that event handling is either addon legacy events or Statamic Static Cache events (not both simultaneously). Addressed in commit 5d80754.

Co-authored-by: eminos <1682784+eminos@users.noreply.github.com>
Copilot AI requested a review from eminos February 20, 2026 10:04
@eminos eminos marked this pull request as ready for review February 20, 2026 10:10
@eminos eminos merged commit 5984d00 into main Feb 20, 2026
3 checks passed
@eminos eminos deleted the copilot/support-static-cache-configuration branch February 20, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support static_cache.php configuration

2 participants