From 9ed823e0af37101dd15e0f8e56587ffc1aefdeba Mon Sep 17 00:00:00 2001 From: Profile Profile Date: Sun, 25 Jan 2026 01:02:17 +0300 Subject: [PATCH] add support menu color in graphql --- block-cache-manager.php | 17 +++++++++++------ template-parts/home/index.php | 10 +++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/block-cache-manager.php b/block-cache-manager.php index 732367e..4f29fa6 100644 --- a/block-cache-manager.php +++ b/block-cache-manager.php @@ -9,17 +9,23 @@ * @param int $expire Время жизни кеша в секундах * @return void */ -function cached_get_template_part( $template, $name = null, $data = [] ) { +function cached_get_template_part( $template, $name = null, $data = [], $ttl = 3600 ) { $fcache = CACHED_TEMPLATE.$template.'.html'; + // Проверяем существование файла и его время жизни if ( file_exists($fcache) ){ - echo file_get_contents($fcache); - return true; + $cache_time = filemtime($fcache); + $current_time = time(); + + // Если кеш не истек, отдаем его + if ( ($current_time - $cache_time) < $ttl ) { + echo file_get_contents($fcache); + return true; + } } $file_directory = dirname($fcache); - ob_start(); get_template_part($template, $name, $data ); @@ -27,7 +33,6 @@ function cached_get_template_part( $template, $name = null, $data = [] ) { echo $content; - if (!file_exists($file_directory)) { if (!wp_mkdir_p($file_directory)) { error_log('Не удалось создать директорию: ' . $file_directory); @@ -41,9 +46,9 @@ function cached_get_template_part( $template, $name = null, $data = [] ) { } return true; - } + // Функция очистки кеша function clear_template_cache ( $template ) { diff --git a/template-parts/home/index.php b/template-parts/home/index.php index 614ed43..43aabde 100644 --- a/template-parts/home/index.php +++ b/template-parts/home/index.php @@ -2,16 +2,16 @@ + cached_get_template_part( 'template-parts/home/news' );?>
- -