Skip to content

Instantly share code, notes, and snippets.

@sebastiandedeyne
Created June 1, 2016 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastiandedeyne/56fe6cba5cf003ec9c9407d60b875602 to your computer and use it in GitHub Desktop.
Save sebastiandedeyne/56fe6cba5cf003ec9c9407d60b875602 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
use MemoizesFunctions;
public function getFoo()
{
return $this->memoize(function () {
return 'foo';
});
}
}
<?php
trait MemoizesFunctions
{
protected function memoize(Closure $function)
{
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
Cache::driver('array')->rememberForever(
"{$caller['class']}::{$caller['function']}",
$function
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment