Skip to content

Instantly share code, notes, and snippets.

@tommoor
Last active December 11, 2015 16:39
Show Gist options
  • Save tommoor/4629529 to your computer and use it in GitHub Desktop.
Save tommoor/4629529 to your computer and use it in GitHub Desktop.
Wrapping cache methods in CI
<?php
protected function cached($key, $callback, $life)
{
$this->load->driver('cache', array('adapter' => 'memcached'));
if (!$response = $this->cache->get($key)) {
$response = $callback($this);
if ($response) {
$this->cache->save($key, $response, $life);
}
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment