SHARE
TWEET

Untitled

a guest Sep 17th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace App\Traits;
  3.  
  4. trait HasMemoization
  5. {
  6.     protected static $memoized = [];
  7.  
  8.     /**
  9.      * Memoize Operation Result
  10.      * @param $key
  11.      * @param \Closure $callback
  12.      * @param bool $refresh
  13.      * @return mixed
  14.      */
  15.     public function memoize($key, \Closure $callback, $refresh = false){
  16.         if(!isset(static::$memoized[$key]) || $refresh){
  17.             return static::$memoized[$key] = $callback();
  18.         }
  19.         return static::$memoized[$key];
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top