Skip to content

Instantly share code, notes, and snippets.

@jpalala
Last active April 22, 2019 02:40
Show Gist options
  • Save jpalala/0e3facc254465d2019af22026304b71a to your computer and use it in GitHub Desktop.
Save jpalala/0e3facc254465d2019af22026304b71a to your computer and use it in GitHub Desktop.
caching in laravel eloquent
/* timeout = seconds */
function cacheDB(array $tags, $depKey, $sql, $timeout = 300) {
$data = DB::select(DB::raw($sql));
return Cache::tags($tags)->put($depKey, $sql);
//remember($depKey, $timeout, function() use($sql) {
// Some join query that will return all Managers from selected Department
return DB::select(DB::raw($sql));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment