2013-02-19 104 views
1

我的YII版本:1.1.12 ...从头开始,我升级到版本1.1.13,但仍然无法正常工作。Yii时间缓存不起作用?

我尝试这样做:

Yii::app()->cache->set('someKey', $auctions); 
$data = Yii::app()->cache->get('someKey'); 
print_r($data); 

而且我看到我存储的数据!但是,如果我试试这个:

Yii::app()->cache->set('someKey', $auctions, 10); 
$data = Yii::app()->cache->get('someKey'); 
print_r($data); 

我什么都看不见?为什么YII会忽略我的时间间隔?我错过了什么?

**编辑**

我的缓存中的配置定义为:

'cache'=>array(
    'class'=>'system.caching.CMemCache', 
    'useMemcached'=>false, 
    'servers'=>array(
     array('host'=>'127.0.0.1', 'port'=> 11211, 'weight'=>60), 
     //array('host'=>'server2', 'port'=>11211, 'weight'=>40), 
    ), 
), 

我知道Memcache的工作,因为我已经与Yii框架之外这个例子中测试了它:

$memcache = new Memcache; 
$memcache->connect("localhost",11211); 
$tmp_object = new stdClass; 
$tmp_object->str_attr = "test"; 
$memcache->set("mysupertest",$tmp_object,false,5); 
var_dump($memcache->get("mysupertest")); 

这个工程和项目缓存5秒......

+0

在你的conf文件并û定义什么类型的高速缓存? – darkheir 2013-02-19 10:11:41

+0

我已更新我的问题,并提供更多信息。 – coderama 2013-02-19 10:23:42

+0

尝试看看'Yii :: app() - > cache-> set('someKey',$ auctions,10);'return'true'或不是 – darkheir 2013-02-19 10:49:15

回答

3

看起来这是CMemCache.php中的一个错误。有这样的功能:

protected function setValue($key,$value,$expire) 
{ 
    if($expire>0) 
    $expire+=time(); 
    else 
    $expire=0; 

    return $this->useMemcached ? $this->_cache->set($key,$value,$expire) : $this->_cache->set($key,$value,0,$expire); 
} 

MEMCACHE不希望被添加的时间,所以我的速战速决是:

protected function setValue($key,$value,$expire) 
{ 
    return $this->useMemcached ? $this->_cache->set($key,$value,$expire) : $this->_cache->set($key,$value,0,$expire); 
} 
+1

报告给Yii github页面。 – ddinchev 2013-02-19 12:30:49

1

好,确保$auctions定义良好。

Yii::app()->cache->set('someKey', array('someValue'), 120); // 120 means 2 minutes 
print_r(Yii::app()->cache->get('someKey')); // you should see the array with the single value, I do see it when I try to run it 

确保配置正常,并且您没有使用CDummyCache。我看起来像这样:

'components' => array(
     ... 
     // Add a cache component to store data 
     // For demo, we are using the CFileCache, you can use any 
     // type your server is configured for. This is the simplest as it 
     // requires no configuration or setup on the server. 
     'cache' => array (
      'class' => 'system.caching.CFileCache', 
     ), 
     ... 
    ), 
+0

我更新了我的问题,即使拍卖设置为“TEST”,但在添加时间的时刻它仍然不起作用。我还能看到什么? – coderama 2013-02-19 10:24:31

+0

那么,你可以打开'CMemCache',看看那里发生了什么。 – ddinchev 2013-02-19 10:34:41

+0

打开CMemCache是​​什么意思? – coderama 2013-02-19 10:35:33