I noticed that the “Object cache for parsed and pre-processed template posts” option is enabled by default. While this improves performance, it can sometimes cause issues during development or dynamic updates.
Would it be possible to expose a hook or public function to programmatically clear this cache? For instance, something like:
php
Copier
do_action('tangible_clear_template_cache');
This would be helpful for developers who want to manually or conditionally reset the cached output for specific templates or globally.
public function to programmatically clear this cache
Here’s the function to delete the cache for a specific template.
use tangible\template_system;
template_system\delete_processed_template_post_cache( $post );
The use statement should be at the top of the file, after any namespace declaration. The delete cache function expects a WP_Post object, so if you have only the ID, you can pass get_post( $id ).
There’s no function to delete cache for all templates, due to the way the cache key (name) is generated from the template post ID. It means there’s no direct way to retrieve all existing cache keys. Instead, you’ll need to get all template IDs, loop through them and remove cache (if any) for each post.