0

我正在尝试通过他们的 API 从 wunderground.com 检索天气,并将其存储在 wincache 中。出于测试目的,我在 News 模型中创建了这个函数:

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() 得到“真”,但是,在尝试读取时我得到“假”。

在新闻控制器中调用以下操作时,随时完成缓存读取

public function diaporama(){
    $this->set('weather', Cache::read('weather'));
}

这是我在 bootstrap.php 中的缓存配置

Cache::config('default', array(
    'engine' => 'Wincache',
    'duration'=> 3600,
    'probability'=> 100,
    'prefix' => ''
));
4

0 回答 0