Search code examples
codeignitercachingcodeigniter-2

Codeigniter object cache doesnt work


I'm trying to save into the cache a json web response, my controller it's pretty simple, here's:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

include_once APPPATH . 'models/presenters/Radio.php';
use Streame\Model\Presenter\Radio as Radio;
use Streame\Model\Presenter\Genre as Genre;

class Test extends MY_Controller {


    public function index(){
        $this->load->driver('cache');
        if (! $cache_data = $this->cache->get('zzz')) {
            $req = $this->send_req('radios', 'GET', array("size" => 5, "phrase" => "rock"));
            $json = $req->json();
            $top_50_radios = Radio::deserializeJsonArray($json["docs"]);
            $cache_data = (object) $top_50_radios;
            $this->cache->save('zzz', $cache_data, 60 * 60 * 12);

            echo "\n</br>NOT CACHEEEEED"; var_dump($cache_data);
        } else {
            echo "\n</br>CACHEEEEED";  var_dump($cache_data);
        }
        shuffle($cache_data);
        $data["random_radio"] = $cache_data[0]->permalink;

    }

}

I got this working when I changed the cache_path in config.php, from nothing to this:

$config['cache_path'] = APPPATH.'../../cache/';

But now, from nowhere, It started to ignore the cache again, the only thing that I get is "NOT CACHED".

I'm running the framework in a nginx server, maybe has something to do with the permissions of the files?


Solution

  • Pretty simple, chmod 777 -R cache/ did the trick.