Skip to content

Instantly share code, notes, and snippets.

@tony-landis
Created December 7, 2008 03:01
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 tony-landis/33019 to your computer and use it in GitHub Desktop.
Save tony-landis/33019 to your computer and use it in GitHub Desktop.
<?php
require "../includes/smarty/Smarty.class.php";
$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'compile';
$smarty->cache_dir = '/var/www/site/tmp';
$smarty->caching = true;
$smarty->force_compile = true;
$smarty->compile_id = '';
$smarty->cache_handler_func = 'server_rewrite_cache_handler';
function server_rewrite_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null)
{
$cache_file = $smarty_obj->cache_dir . '/' . $compile_id . $cache_id;
if(!is_file($cache_file)) {
$base_file = basename($cache_file);
$base_dir = dirname($cache_file);
if(!is_dir($base_dir)) mkdir($base_dir, 0777, true);
}
switch ($action) {
case 'read':
if(!is_file($cache_file)) return false; else return true;
break;
case 'write':
return file_put_contents($cache_file, $cache_content);
break;
case 'clear':
return @unlink($cache_file);
break;
default:
return false;
break;
}
}
$_p = $_REQUEST['p']; // detect the actual file path requested so I can save the cached copy with the correct path and filename
$page = ''; // my logic here to determine the correct smarty template to display
$smarty->display($page, $_p);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment