Unable to save to wincache from cakePHP shell

Posted by Phillaf on Stack Overflow See other posts from Stack Overflow or by Phillaf
Published on 2012-11-21T16:33:27Z Indexed on 2012/11/21 16:59 UTC
Read the original article Hit count: 376

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about cakephp

Related posts about caching