Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
class cache
{
var $cache_dir = './wt/cache/';//Това е директорията, където ще се съхраняват кеш файловете.
var $cache_time = 1000;//Колко време ще продължи кеш файлове за секунди.
var $caching = false;
var $file = '';
function cache()
{
//Конструктор на класа
$this->file = $this->cache_dir . urlencode( $_SERVER['REQUEST_URI'] );
if ( file_exists ( $this->file ) && ( fileatime ( $this->file ) + $this->cache_time ) > time() )
{
//Взимаме кеша
$handle = fopen( $this->file , "r");
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
echo $data;
} while (true);
fclose($handle);
exit();
}
else
{
//Създаваме кеша :
$this->caching = true;
ob_start();
}
}
function close()
{
//Трябва да имаме това в края на всяка страница
if ( $this->caching )
{
//Кеширване на съдържанието и го показваме в файл
$data = ob_get_clean();
echo $data;
$fp = fopen( $this->file , 'w' );
fwrite ( $fp , $data );
fclose ( $fp );
}
}
}
//Пример:
$ch = new cache();
echo date("D M j G:i:s T Y");
$ch->close();
?>