Skip to content

Block API : cache #29

@Rahe

Description

@Rahe

Implement a cache for the rendered template in front for ACF/Dynamic blocs.

For now, the Dynamics blocs are rendered on every load in the backend and in the frontend, to speed up the process it's not usefull to render this everytime.

Before sending the template :

		$template = Helpers::locate_template( $tpl_slug );
		if ( empty( $template ) ) {
			return;
		}
		$filetime = filemtime( $template );
		$content = wp_cache_get( $this->cache_key( $slug,$post_id,$block_data, $filetime ), 'bea-plugin-boilerplate-blocks', false, $found );
		if ( $found === true ) {
			echo $content;
			return;
		}

And then if rendered

wp_cache_set( $this->cache_key( $render, $filetime ), $content, 'bea-plugin-boilerplate-blocks' );

The cache_key method

	private function cache_key($slug,$post_id,$block_data, $filetime ) {
		return $filetime.':'.$slug . ':' . $post_id. ':' . md5( serialize( $block_Data) ) ) . ':' . wp_cache_get_last_changed( 'posts' );
	}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions