Skip to content

Instantly share code, notes, and snippets.

@dodyw
Created October 29, 2014 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodyw/36f8b07130399f0c28ca to your computer and use it in GitHub Desktop.
Save dodyw/36f8b07130399f0c28ca to your computer and use it in GitHub Desktop.
This is taken from indexu 7 (categorypage.php)
// this is on top
ob_start();
// this is the content
..
..
..
// this is in the bottom
if ($lep->config['enable_page_caching']) { // if cache setting is enabled, read from cache
etc_cache_build('01');
ob_end_clean();
etc_cache_read('01');
}
else { // else just output the content without cache
ob_end_flush();
}
///////////////// cache function, in /etc_function.php
function etc_cache_build($page_code) {
global $lep;
if ($page_code=='00') {
$naming = "/index.php";
}
elseif ($page_code=='01') {
$naming = "/".$lep->input['id'].".php";
}
elseif ($page_code=='02') {
$naming = "/".$lep->input['id'].".php";
}
$cache_dir = PATH . 'cache/pages/';
if (!is_dir($cache_dir)) {
mkdir(substr($cache_dir,0,strlen($cache_dir)-1), 0777);
}
if (!is_dir($cache_dir.$page_code)) {
mkdir($cache_dir.$page_code, 0777);
}
$cache_file = $cache_dir . $page_code . $naming;
$footprint = "\n\n<!-- indexu page cache : ".date('d M Y - H:i:s')." -->";
$fp = fopen($cache_file, 'w+');
fwrite($fp, ob_get_contents().$footprint);
fclose($fp);
}
function etc_cache_read($page_code) {
global $lep;
$duration = 0;
if ($lep->config['page_caching_duration_base']=='minute') {
$duration = 60;
}
elseif ($lep->config['page_caching_duration_base']=='hour') {
$duration = 60 * 60;
}
elseif ($lep->config['page_caching_duration_base']=='day') {
$duration = 60 * 60 * 24;
}
if ($page_code=='00') {
$naming = "/index.php";
$cache_timeout = $lep->config['page_caching_index_timeout'] * $duration;
}
elseif ($page_code=='01') {
$naming = "/".$lep->input['id'].".php";
$cache_timeout = $lep->config['page_caching_category_timeout'] * $duration;
}
elseif ($page_code=='02') {
$naming = "/".$lep->input['id'].".php";
$cache_timeout = $lep->config['page_caching_detail_timeout'] * $duration;
}
$cache_dir = PATH . 'cache/pages/';
$cache_file = $cache_dir . $page_code . $naming;
if (file_exists($cache_file) && time() - $cache_timeout < filemtime($cache_file)) {
include $cache_file;
etc_runtime();
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment