Skip to main content

benecaster_feed_cache_cleared

Action Premium

Fires after any Benecaster feed cache clear completes, regardless of what triggered it. Trigger sources include: external code calling benecaster_clear_feed_cache, Benecaster’s own internal invalidation from the episode editor, Settings saves, or REST endpoints, the admin UI cache-clearing buttons, and the WP-CLI wp benecaster cache clear command.

Use it to warm the cache immediately after a clear, log the event to a monitoring service, or trigger related invalidations in connected systems. The cache is already fully cleared when this hook fires.

A fourth scope, plugin_update, behaves unlike the other three — see the parameter note below.

Parameters

Name Type Default Description
$scope string One of `global`, `show`, `tier`, or `plugin_update`. `plugin_update` fires when Benecaster's own plugin file is part of a completed install or update, because feed XML structure can change between versions and the cache key cannot detect that. A `switch` on this value that assumes three cases will silently take its default branch on the fourth.
$show_id int|null Show ID if scope is `show` or `tier`, otherwise null. On `plugin_update` it is `0`, not `null` — the clear is site-wide and belongs to no single show. Callbacks testing `null === $show_id` to mean "site-wide" will not match this scope.
$tier_slug string|null Tier slug if scope is `tier`, otherwise null. On `plugin_update` it is an empty string `''`, not null.

Examples

Log all cache clears to error log

add_action( 'benecaster_feed_cache_cleared', function (
    string  $scope,
    ?int    $show_id,
    ?string $tier_slug
): void {
    error_log( sprintf(
        '[Benecaster] Feed cache cleared — scope: %s, show: %s, tier: %s',
        $scope,
        $show_id ?? 'all',
        $tier_slug ?? 'all'
    ) );
}, 10, 3 );

Warm all feeds after a global clear

add_action( 'benecaster_feed_cache_cleared', function (
    string  $scope,
    ?int    $show_id,
    ?string $tier_slug
): void {
    if ( 'global' !== $scope ) {
        return; // Only warm on global clears.
    }

    // Trigger a feed request for each active show + tier combination.
    my_addon_warm_all_feeds();
}, 10, 3 );

Notes

This hook fires on every cache clear including those triggered internally by Benecaster, not only when your own code calls benecaster_clear_feed_cache. If your callback should respond only to clears your code triggered, set a flag before calling the action and check it inside the callback.

Need this built rather than just documented? See our services →