Caching 时间缓存不起作用?

Caching 时间缓存不起作用?,caching,yii,Caching,Yii,我的YII版本:1.1.12。。。我升级到1.1.13版,但仍然无法正常工作 我试过这个: Yii::app()->cache->set('someKey', $auctions); $data = Yii::app()->cache->get('someKey'); print_r($data); 我看到了我存储的数据!但是,如果我尝试这样做: Yii::app()->cache->set('someKey', $auctions, 10); $data

我的YII版本:1.1.12。。。我升级到1.1.13版,但仍然无法正常工作

我试过这个:

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秒钟…

好吧,请确保
$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',
       ),
       ...
   ),

那么,请确保
$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',
       ),
       ...
   ),

这似乎是CMemCache.php中的一个bug。有以下功能:

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);
}

这似乎是CMemCache.php中的一个bug。有以下功能:

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);
}


在您的conf文件中,您定义了什么类型的缓存?我已经用更多信息更新了我的问题。请尝试查看
Yii::app()->cache->set('someKey',$auctions,10)返回
true
或不返回。。。。。但不知何故,1秒钟后,缓存被设置为false,即使我在你的conf文件中填充了一些东西……你定义了什么类型的缓存?我已经用更多信息更新了我的问题。试着看看
Yii::app()->cache->set('someKey',$auctions,10)返回
true
或不返回。。。。。但不知何故,1秒钟后,缓存被设置为false,即使我用一些东西填充它……我更新了我的问题,即使拍卖被设置为“测试”,它在我添加时间的那一刻仍然不起作用。我还可以看什么?好的,你可以打开
CMemCache
看看那里发生了什么。你说打开CMemCache是什么意思?这是Yii framework中的文件-
CMemCache.php
,找到了
framework/system/caching/CMemCache.php
。打开它的
set
方法并调试它所做的事情。现在检查一下。我还没有看到任何明显的迹象。我更新了我的问题,即使拍卖设置为“测试”,在我添加时间的那一刻它仍然不起作用。我还可以看什么?好的,你可以打开
CMemCache
看看那里发生了什么。你说打开CMemCache是什么意思?这是Yii framework中的文件-
CMemCache.php
,找到了
framework/system/caching/CMemCache.php
。打开它的
set
方法并调试它所做的事情。现在检查一下。我还没有看到任何明显的东西。报告给Yii github页面。报告给Yii github页面。