<?
 
    
 
    
 
    function SmartyBridge_Cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null){
 
        global $cache_obj;
 
        $CacheID = md5($tpl_file.$cache_id.$compile_id);
 
        
 
 
        $dsn = 'memcache://127.0.0.1:11211';
 
        
 
//        $dsn = 'sqlite://sqlite.db';
 
        
 
        $cache_obj = isset($cache_obj) && is_object($cache_obj) ? $cache_obj : CacheMeLoader::Factory($dsn);
 
                //$cache_obj->lifetime = $smarty_obj->cache_lifetime;
 
        
 
        //die();
 
        switch ($action) {
 
                        case 'read':
 
                $cache_content = $cache_obj->get($CacheID);
 
                return $cache_content;
 
            break;
 
            case 'write':
 
 
                return $cache_obj->set($CacheID, $cache_content);
 
            break;
 
            case 'clear':
 
                if(empty($cache_id) && empty($compile_id) && empty($tpl_file)) {
 
                    return $cache_obj->clear();
 
                } else {
 
                    return $cache_obj->clear($cache_id);                
 
                }
 
            break;
 
            default:
 
                $smarty_obj->_trigger_error_msg("cache_handler: unknown action \"$action\"");
 
            break;
 
        }    
 
 
    }
 
    
 
    include 'libs/Smarty/Smarty.class.php';
 
    include dirname(dirname(__FILE__)).'/Cacheme/Cacheme.php';
 
    $smarty = new Smarty;
 
    $smarty->cache_handler_func = 'SmartyBridge_Cache_handler';
 
    $smarty->template_dir = dirname(__FILE__).'/';
 
    $smarty->compile_dir  = dirname(__FILE__).'/';
 
    $smarty->cache_dir      = dirname(__FILE__).'/_tmp/_tmp_templates_cache';
 
    $smarty->force_compile = false;
 
    $smarty->caching = true;
 
        $smarty->cache_lifetime = 5;
 
    
 
    $var = 'me cached  ';
 
    if ($smarty->is_cached('test.tpl', $var)){
 
        $smarty->display('test.tpl', $var);    
 
        die(' @cached');
 
    } else {
 
        $smarty->assign('var', $var);
 
                $smarty->display('test.tpl', $var);    
 
        die(' @generated');        
 
    }
 
    
 
?>
 
 |