Unable to save to wincache from cakePHP shell
- by Phillaf
I'm trying to retrieve the weather from wunderground.com through their API, and store it in wincache. For testing purposes I made this function in the News model:
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);
}
It works fine when I call this from the controller. However, I can't figure why that same function doesn't work when called from the console. I made this shell in order to eventually add this to windows task scheduler.
class WeatherShell extends AppShell {
public $uses = array('News');
public function main() {
$this->News->updateWeather();
}
}
When running this, I see that $results is correctly populated. I get 'true' from Cache::write(), however, I get 'false' when trying to read. What subtlety am I missing?