无法从cakePHP shell保存到wincache
我正试图通过他们的API从wunderground.com检索天气,并将其存储在wincache中。出于测试目的,我在新闻模型中创建了此函数:无法从cakePHP shell保存到wincache,cakephp,caching,Cakephp,Caching,我正试图通过他们的API从wunderground.com检索天气,并将其存储在wincache中。出于测试目的,我在新闻模型中创建了此函数: public function updateWeather(){ $results = file_get_contents('http://api.wunderground.com/api/**api_key**/conditions/q/CA/Montreal.json'); $results = json_decode($result
public function updateWeather(){
$results = file_get_contents('http://api.wunderground.com/api/**api_key**/conditions/q/CA/Montreal.json');
$results = json_decode($results);
return Cache::write('weather', $results);
}
当我从控制器调用它时,它工作正常。但是,我不明白为什么从控制台调用时,相同的函数不起作用。我制作这个shell是为了最终将它添加到windows任务调度程序中
class WeatherShell extends AppShell {
public $uses = array('News');
public function main() {
$this->News->updateWeather();
}
}
调试时,我看到$results已正确填充。我从Cache::write()中得到“true”,但在尝试读取时得到“false”
在新闻控制器中调用以下操作时,缓存读取随时完成
public function diaporama(){
$this->set('weather', Cache::read('weather'));
}
这是我在bootstrap.php中的缓存配置
Cache::config('default', array(
'engine' => 'Wincache',
'duration'=> 3600,
'probability'=> 100,
'prefix' => ''
));
您没有公布如何读取缓存。也许时间限制太短了?我编辑了这篇文章,添加了阅读和配置部分。至于时间限制,我尝试调用cache::read缓存::write后面的行,这样实际上就不会有延迟。我得到了相同的结果。您如何断言“即使缓存尚未生成或过时”,结果始终可用?这样看来,您是在自找麻烦。我计划断言该值存在于控制器中的diporama()中。(这就是您所说的“assert”吗?)但现在,我认为在手动调试时尽可能简化问题就足以查看是否可以读取/写入缓存。