Skip to content

Instantly share code, notes, and snippets.

@Casperhr
Created July 20, 2015 20:26
Show Gist options
  • Select an option

  • Save Casperhr/3d5e268a6a44e8b4204d to your computer and use it in GitHub Desktop.

Select an option

Save Casperhr/3d5e268a6a44e8b4204d to your computer and use it in GitHub Desktop.
public function getAllForAPI()
{
// Lets try to look up in cache, hopefuly there is something there
$contacts = Cache::get('contacts')
// Is there something?
if(!empty($contacts) {
// Yep, lucky us, let's just return that instead of wasting time in DB
return $contacts;
}
// Looking up in db
$contacts = $this->orderBy('name', 'ASC')->get();
// Let's cache it, so next time we can skip this long lookup
Cache::put('contacts', $contacts, 1440);
return $contacts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment