Skip to content

Instantly share code, notes, and snippets.

@InnaTarasyan
Created November 29, 2025 16:35
Show Gist options
  • Select an option

  • Save InnaTarasyan/987db600b9eb32e1643ae720f4ac21af to your computer and use it in GitHub Desktop.

Select an option

Save InnaTarasyan/987db600b9eb32e1643ae720f4ac21af to your computer and use it in GitHub Desktop.
cachef() — Cache & Return Closure Result in One Line
// app/helpers.php
if (! function_exists('cachef')) {
function cachef($key, $seconds, Closure $callback)
{
return Cache::remember($key, $seconds, $callback);
}
}
// Usage
$users = cachef('active_users', 60, fn() => User::active()->get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment