Dynamic blocks
Block output caching
Opt in to WordPress object-cache storage for expensive, context-stable dynamic output.
#Enable per block
Register this from the theme file loaded by functions.php. A TTL of 300 caches matching output for five minutes.
<?php
defined('ABSPATH') || exit;
use Voxyframe\Core\Registry;
add_action('voxycure/register', function (Registry $registry): void {
$registry->register_block('project-grid', [
'label' => 'Project grid',
'template' => get_theme_file_path('blocks/project-grid.php'),
'cache_ttl' => 300,
'fields' => [],
]);
});#Cache key inputs
The cache key contains the block ID, serialized attributes, current post ID, and locale. A persistent object-cache plugin is required for values to survive between PHP requests.
#Central cache policy
add_filter('voxycure_block_cache_ttl', function (int $ttl, string $blockId): int {
return 'project-grid' === $blockId ? HOUR_IN_SECONDS : $ttl;
}, 10, 2);