怎么样刷新缓存文件我在一个循环里写了  判断一下(当数组a的长度小于1时就执行一次) 写进缓存的操作,反之,不执行写进缓存的操作。问题就出来这儿当执行到 数组a 小于1时,就写一次缓存b.txt  然后我立既读这个缓存b.txt文件(我用记事本打开b.txt,可以得到正确的内容),而得到的是一个错误的结果 还是数组a的值,并没有变化,只有当我在执行一下这个方法时,才能读到这个b.txt 文件。我在该怎么做?才能解决这个问题。

解决方案 »

  1.   

      $urlArray = cache::get('tuangouBaiduType');
    echo "<pre>a";print_r($urlArray);  //$urlArray 为 空
      if(count($urlArray)<=1){
       cache::init("php");
       $type = array('a','b','c','d');
       cache::set('tuangouBaiduType',$type); 
      }
    cache::init("php");
       $urlArray = cache::get('tuangouBaiduType');
      
    echo "<pre>d";print_r($urlArray);  // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的
      

  2.   

    $urlArray = cache::get('tuangouBaiduType');
    echo "<pre>a";print_r($urlArray); //$urlArray 为 空
       if(count($urlArray)<=1){
    cache::init("php");
    $type = array('a','b','c','d');
    cache::set('tuangouBaiduType',$type);  
       }
    cache::init("php");
      $urlArray = cache::get('tuangouBaiduType');
      
    echo "<pre>d";print_r($urlArray); // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的
      

  3.   

    读之前,使用fclose了吗,另外把问题简单化,把代码从项目中提练出来,(提练本身也是分析问题),然后再测试.
      

  4.   

    算我没说,你先看下cache类吧。没人知道它怎么实现缓存了
      

  5.   

    读他是用的file_put_contents($this->getFile($id),'<?php return array('.$expire.','.var_export($value, true).');',LOCK_EX);
      

  6.   


    public function set($id,$value,$expire=0)
    {
    //echo "<pre>";echo "a";print_r($value);exit();
      file_put_contents($this->getFile($id),'<?php return array('.$expire.','.var_export($value, true).');',LOCK_EX);
    }
    public function get($id)
    {
    $cFile = $this->getFile($id);
    if (file_exists($cFile))
    {
                $data = include $cFile;
                if(SYSTIME < $data[0] || $data[0] == 0)
                {
                    return $data[1];
                }else
                {
                    @unlink($cFile);
                }
            }
            return false;
    }
      

  7.   

    问题不出在文件读写,应该检查整个逻辑
    当然也不排除你不能通过下面的测试例file_put_contents('zzz', 'a');
    $s = file_get_contents('zzz');
    echo $s;$fp = fopen('zzz', 'w');
    fwrite($fp, 'b');
    $fp = fopen('zzz', 'r');
    echo fgets($fp);ab
      

  8.   


    <?php file_put_contents("1.txt","aabbcc",LOCK_EX);
    $a = file_get_contents('1.txt');
    echo $a;
    ?>
    这这样写了一个都得行