Compare commits
2 Commits
ed66701325
...
ddf44fbfad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddf44fbfad | ||
|
|
9ed823e0af |
@@ -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 ) {
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ require "inc/meta_keywords.php";
|
||||
require "inc/journal_issue.php"; //номера журналов
|
||||
require "inc/rank-description.php";
|
||||
|
||||
//utils
|
||||
require "utils/acf-category.php";
|
||||
|
||||
//scheduler
|
||||
require "inc/schedule_async_post_processing.php";
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
|
||||
<?php //get_template_part("template-parts/home/news");
|
||||
cached_get_template_part( 'template-parts/home/news' );?>
|
||||
cached_get_template_part( 'template-parts/home/news' );?>
|
||||
|
||||
<div class="col-12 col-md-8 col-xl-6 float-left">
|
||||
|
||||
<?php //get_template_part("template-parts/home/main-item");
|
||||
cached_get_template_part( 'template-parts/home/main-item' );
|
||||
<?php get_template_part("template-parts/home/main-item");
|
||||
//cached_get_template_part( 'template-parts/home/main-item' );
|
||||
?>
|
||||
|
||||
<?php //get_template_part("template-parts/home/colon-item");
|
||||
cached_get_template_part( 'template-parts/home/colon-item' );
|
||||
<?php get_template_part("template-parts/home/colon-item");
|
||||
//cached_get_template_part( 'template-parts/home/colon-item' );
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user