Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created September 6, 2012 22:11
Show Gist options
  • Save glynrob/3660768 to your computer and use it in GitHub Desktop.
Save glynrob/3660768 to your computer and use it in GitHub Desktop.
Memcache Comparison in Codeigniter
$cachetime = 10; // number of seconds to cache for
$data = array();
$data['cachereset'] = 0;
// cache calls
$startTime = microtime(true);
$this->load->driver('cache');
$cache = $this->cache->memcached->get('alluserscount');
if (!$cache){
$data['cachereset'] = 1;
$this->load->model('Users','',TRUE);
$cache = $this->Users->getAll();
$this->cache->memcached->save('alluserscount',$cache, $cachetime);
}
$data['cache_result'] = $cache;
$data['cache_time'] = microtime(true)-$startTime;
// normal query calls
$startTime = microtime(true);
$this->load->model('Users','',TRUE);
$data['normal_result'] = $this->Users->getAll();
$data['normal_time'] = microtime(true)-$startTime;
$this->load->view('comparision',$data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment