Inicio - Documentación - POM Cache - 09 Developers - Clear caches from application code

Clear caches from application code

Use POM Cache's high-level helpers after custom data changes that affect a public representation. HTML and progressive JSON are independent; clear only the store whose output changed.

Clear current-site HTML

if ( function_exists( 'pom_cache_delete_site_cache' ) ) {
    $cleared = pom_cache_delete_site_cache( 'my_plugin_catalog_sync' );
}

pom_cache_delete_site_cache( $context ) returns true when the high-level deletion proceeds and false when a filter vetoes it.

Use a stable, lowercase integration context. The default rewrite-rule flush occurs only for manual and manual_ajax; a custom context avoids that expensive side effect unless a filter deliberately enables it.

Clear current-site progressive JSON

if ( function_exists( 'pom_cache_json_delete_site_cache' ) ) {
    $cleared = pom_cache_json_delete_site_cache(
        'my_plugin_catalog_sync'
    );
}

The JSON helper consults the shared site-deletion gate and then the JSON-specific gate. It clears the entire progressive JSON tree for the current site.

Clear both stores

When a change affects the initial HTML and later progressive payloads:

function my_plugin_clear_public_catalog_cache() {
    $context = 'my_plugin_catalog_sync';

    if ( function_exists( 'pom_cache_delete_site_cache' ) ) {
        pom_cache_delete_site_cache( $context );
    }

    if ( function_exists( 'pom_cache_json_delete_site_cache' ) ) {
        pom_cache_json_delete_site_cache( $context );
    }
}

Do not assume the first helper clears JSON. The admin-bar shortcut calls both behaviors, but the PHP helpers remain explicit.

Invalidate after a post change

For code that already has a post:

if ( function_exists( 'pom_cache_delete_site_cache_for_post' ) ) {
    pom_cache_delete_site_cache_for_post(
        $post_id,
        get_post( $post_id ),
        'my_plugin_post_sync'
    );
}

The HTML helper:

  • returns the post ID, not a success boolean;
  • skips invalid IDs, revisions, autosaves, missing posts, and non-viewable post types;
  • suppresses a duplicate last post within the request;
  • applies pom_cache_clear_post_cache;
  • clears the current site's full HTML store when allowed.

pom_cache_json_delete_site_cache_for_post() has the corresponding JSON behavior and returns the post ID.

Target one JSON file

When your integration owns a known relative path:

$relative_path = 'archive/book/page-2.json';

if (
    function_exists( 'pom_cache_json_delete' )
    && function_exists( 'pom_cache_json_normalize_relative_path' )
    && '' !== pom_cache_json_normalize_relative_path( $relative_path )
) {
    pom_cache_json_delete(
        $relative_path,
        array( 'context' => 'my_plugin_book_update' )
    );
}

pom_cache_json_delete() returns true only when an existing exact file is removed. It does not require the JSON master switch to be enabled.

Avoid the low-level HTML helper

pom_cache_clear_cache( $blog_id ) performs a low-level HTML prune and fires pom_cache_cleared, but it bypasses the shared high-level deletion gate. Application integrations should normally call pom_cache_delete_site_cache() instead.

Multisite

Helpers use the current blog context. To target another site, authorize the operation, call switch_to_blog(), use the high-level helpers, and restore the original blog in a finally block.

Clearing origin files never invalidates a CDN. Coordinate edge invalidation after the source and origin representations are correct.