lzb/cache_cleared
Fires once every lzb_blocks_cache_ transient has been deleted, so anything you built on top of the block list can be rebuilt at the same moment.
A page cache holding rendered blocks, or your own index built from get_blocks(), goes stale on exactly the same events that invalidate the Lazy Blocks cache. Hooking this action saves you from listing those events again.
The action takes no arguments. It is the last statement of clear_blocks_cache(), after the transients are gone and after the in-memory block list and the cache key hash have been reset, so a handler calling lazyblocks()->blocks()->get_blocks() gets a freshly built list rather than the one that was just thrown away.
Triggers
| Event | Fires when |
|---|---|
save_post_lazyblocks | a block is saved in the block builder |
delete_post, wp_trash_post, untrash_post | the post is of the lazyblocks type |
activated_plugin, deactivated_plugin, switch_theme | always |
upgrader_process_complete | the update was a plugin or a theme |
| Clear Cache link on the Lazy Blocks screen | the nonce checks out and the user has manage_options |
lazyblocks()->blocks()->clear_blocks_cache() | called from your own code |
Usage
function my_lzb_cache_cleared() {
// Our block index is built from get_blocks(), so it goes stale at
// exactly the same moments the plugin's own cache does.
delete_transient( 'acme_block_index' );
// WP Super Cache holds rendered pages containing those blocks.
if ( function_exists( 'wp_cache_clear_cache' ) ) {
wp_cache_clear_cache();
}
}
add_action( 'lzb/cache_cleared', 'my_lzb_cache_cleared' );Nothing is passed in, so a handler cannot tell which trigger it came from. Activating a plugin fires it once per plugin, and a bulk activation of ten plugins fires it ten times, so keep the work here cheap or debounce it yourself.
Available since Lazy Blocks 4.2.0. How long the cache lives in the first place is lzb/cache_expiration.