Welcome Guest, Not a member yet? Register   Sign In
Issue with Phil Sturgeon's Codeigniter-Cache library
#1

[eluser]Unknown[/eluser]
Hi guys, I've been struggling to get the library to work for a couple of days now, so I think it's time I asked what I'm doing wrong :p

I'm using:
Vanilla CI Install (2.1.4)
Codeigniter-Cache - https://github.com/philsturgeon/codeigniter-cache

The problem I'm having is, upon running the database query, a cache file is created but the results from the database are not stored in it.
To add to my confusion, the results appear on the page upon first load, but then upon page refresh, the cached file is then loaded instead, so no data is retrieved.

Here's my controller - users.php
Code:
class Users extends CI_Controller {

public function test()
{
  $this->output->enable_profiler(TRUE);
  $this->load->model('mdl_users');

  $id = 2;
  $data['query'] = $this->cache->model('mdl_users', 'get_user', array($id), 120);
  
  $this->load->view('users', $data);
}

}

My model - mdl_users.php
Code:
class Mdl_users extends CI_Controller {

function get_user($id)
{
  $this->db->where('id', $id);
  $this->db->limit(1);
  $query=$this->db->get('users');
  return $query;
}

}

and my view - users.php
Code:
<?php
foreach($query->result() as $row)
{
  echo $row->name;
}
?>

And this is what is stored in the cache file

Code:
a:4:{s:16:"__cache_contents";O:19:"CI_DB_mysqli_result":8:{s:7:"conn_id";O:6:"mysqli":19:{s:13:"affected_rows";N;s:11:"client_info";N;s:14:"client_version";N;s:13:"connect_errno";N;s:13:"connect_error";N;s:5:"errno";N;s:5:"error";N;s:10:"error_list";N;s:11:"field_count";N;s:9:"host_info";N;s:4:"info";N;s:9:"insert_id";N;s:11:"server_info";N;s:14:"server_version";N;s:4:"stat";N;s:8:"sqlstate";N;s:16:"protocol_version";N;s:9:"thread_id";N;s:13:"warning_count";N;}s:9:"result_id";O:13:"mysqli_result":5:{s:13:"current_field";N;s:11:"field_count";N;s:7:"lengths";N;s:8:"num_rows";N;s:4:"type";N;}s:12:"result_array";a:0:{}s:13:"result_object";a:0:{}s:20:"custom_result_object";a:0:{}s:11:"current_row";i:0;s:8:"num_rows";i:1;s:8:"row_data";N;}s:15:"__cache_created";i:1401965162;s:20:"__cache_dependencies";a:0:{}s:15:"__cache_expires";i:1401965182;}

I'm not a total noob to CI, and this is the simplified code to test it before using it for my production website. I'm totally stuck here though.
#2

[eluser]albertleao[/eluser]
First issue I'm seeing is that your model is extending CI_Controller
#3

[eluser]Unknown[/eluser]
*facepalm* Thanks, didn't spot that! Smile I've changed it to CI_Model

Still having the same problem however.
#4

[eluser]CroNiX[/eluser]
You might get more help if you created an issue in that github repository.




Theme © iAndrew 2016 - Forum software by © MyBB