---
title: "lzb/cache_cleared"
description: "PHP action `lzb/cache_cleared` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/php-actions/lzb-cache_cleared/"
source: "php-actions/lzb-cache_cleared.mdx"
---
# 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

```php title="PHP"
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](https://www.lazyblocks.com/docs/php-filters/lzb-cache_expiration/).

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
