用smarttemplate的缓存不符合你的要求吗?

解决方案 »

  1.   

    我把上面的源代码精简了一下:<?
    $cache  =  new SmartCache();
    $cache->cache_dir='';
    $cache->start(); 
    echo "bbbbbbbb";class SmartCache{
    function SmartCache ( $key = '' ) {
            if (empty($key)) $key  =  $_SERVER['REQUEST_URI'];
            $this->filename  =  'cache_' . md5(serialize($key)) . '.ser';
    }
        function start( $timeout = 0 ){
    if ($output = $this->read($timeout)) exit ($output);
    else ob_start( array( &$this, 'callback' ) );
    }
    function read ( $timeout = 0 ) {
    if (@is_file($this->cache_dir . $this->filename)) {
    if ((time() - filemtime($this->cache_dir . $this->filename)) < $timeout) {
    $serialized  =  file_get_contents($this->cache_dir . $this->filename);
    return unserialize($serialized);
                }
            }
        }
        function callback ( $output ) {
            writetofile($this->cache_dir . $this->filename, serialize($output));
            return $output;
        }}function writetofile($file_name,$data,$method="w") {
    $filenum=@fopen($file_name,$method);
    @fwrite($filenum,$data);
    @fclose($filenum);
    }
      

  2.   

    自带的缓存好用啊,我试过的
    设置好缓存路径和时间就可以了$_CONFIG['smarttemplate_cache'] = IB_TEMP;
    $_CONFIG['cache_lifetime'] = 600; //缓存10分钟$tpl = new SmartTemplate( "test.htm" );
    $tpl->use_cache();
      

  3.   

    大家试验我那段代码能够成功吗?我这里总是失败。
    to 稻草人:你那个好用是因为你整个程序没有其他ob函数。而我的程序本身还有其他函数,并且我需要用的是分块,这样可能会多次使用ob回调,这样肯定不能实现了。对吧?