Skip to content

Instantly share code, notes, and snippets.

@joshtronic
Created September 19, 2012 19:17
Show Gist options
  • Save joshtronic/3751629 to your computer and use it in GitHub Desktop.
Save joshtronic/3751629 to your computer and use it in GitHub Desktop.
// {{{ Flush User Cache
public function flushCache($user_id)
{
$this->cache->delete('USER-' . $user_id);
}
// }}}
// {{{ Get User (by Column)
private function getUser($column, $value)
{
if ($column == 'id')
{
$user = $this->cache->get('USER-' . $value);
}
else
{
$user = false;
}
if ($user == false)
{
$user = new User(array(
'fields' => $this->cached_fields,
'conditions' => array($column => $value)
));
if ($user->count() == 1)
{
$user = $user->record;
$this->cache->set('USERNAME-' . $user['username'], $user['id'], TIME_HOUR);
$this->cache->set('USER-' . $user['id'], $user, TIME_HOUR);
}
else
{
$user = null;
}
}
return $user;
}
// }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment