2013-02-19 108 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