Answer the question
In order to leave comments, you need to log in
How to cache json?
Tell me what's wrong?
$cached = fopen($cache_file, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush();
$file = 'site.com/json/liveu.json';
$cache_path = "/wp-content/tmp"; // папка с кэш-файлами на сервере
$cache_file = sprintf($file, $cache_path);
$cache_ttl = 900; // время жизни кэша в секундах
$html = ''; // HTML код для вставки на страницу
if( file_exists( $cache_file) && (time() - filemtime($cache_file)) < $cache_ttl) {
// берём кэшированные данные
$html = file_get_contents($file);
file_put_contents($cache_file, $html);
}
echo $html;
Answer the question
In order to leave comments, you need to log in
Everything is very, very bad.
если (файл_с_кешем_существует И кеш_не_протух)
получить_данные_с_сайта
записать_данные_в_кеш
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question