function get_posts_ajax_handler() { $cache_file = '/path/to/cache/directory/cache_file.txt'; if (file_exists($cache_file) && (time() - filemtime($cache_file)) < 3600) { $response = file_get_contents($cache_file); echo $response; wp_die(); } $posts = // Our content $response = json_encode($posts); file_put_contents($cache_file, $response); echo $response; wp_die(); } add_action('wp_ajax_get_posts', 'get_posts_ajax_handler'); add_action('wp_ajax_nopriv_get_posts', 'get_posts_ajax_handler');

Create custom caching WordPress
More
lil-code© | 2022 - 2025
Go Top