Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Traits;
- trait HasMemoization
- {
- protected static $memoized = [];
- /**
- * Memoize Operation Result
- * @param $key
- * @param \Closure $callback
- * @param bool $refresh
- * @return mixed
- */
- public function memoize($key, \Closure $callback, $refresh = false){
- if(!isset(static::$memoized[$key]) || $refresh){
- return static::$memoized[$key] = $callback();
- }
- return static::$memoized[$key];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement