Factory Method to return appropriate driver instance.

@param          $cache
@param callable $callback
@throws \RuntimeException
@return mixed
977989
public static function make($cache, \Closure $callback)
    {
        // Return Closure callback
        if (array_key_exists($cache, static::$drivers)) {
            return static::getCacheDriver($callback, $cache);
        }

        throw new \RuntimeException('Cache driver not found!');
    }
878935
public function setResultCacheDriver($resultCacheDriver = null)
    {
        if ($resultCacheDriver !== null && ! ($resultCacheDriver instanceof \Doctrine\Common\Cache\Cache)) {
            throw ORMException::invalidResultCacheDriver();
        }

        $this->_queryCacheProfile = $this->_queryCacheProfile
            ? $this->_queryCacheProfile->setResultCacheDriver($resultCacheDriver)
            : new QueryCacheProfile(0, null, $resultCacheDriver);

        return $this;
    }
1075400
public static function get(string $key, callable $callback)
    {
        $item = static::getItem($key);

        if (!$item)
        {
            return static::syncCache($key, $callback);
        }

        if (!$item->isHit())
        {
            $item->set(
                static::syncCache($key, $callback)
            );

            static::getPool()->save($item);
        }

        $cache = static::getCache($key);

        if ($cache)
        {
            return $cache;
        }

        return $item->get();
    }
122020
private function run($callback)
    {
        $injects = [];
        $reflectionFunction = new \ReflectionFunction($callback);
        foreach ($reflectionFunction->getParameters() as $parameter) {
            if ($class = $parameter->getClass()) {
                $injects[] = app($class->name);
            }
        }

        return call_user_func_array($callback, $injects);
    }
264540
protected function sear($key, callable $callback)
    {
        if (is_null($value = $this->cache->get($key))) {
            $this->cache->forever($key, $value = $callback());
        }

        return $value;
    }
728590
private function createResource(callable $callback)
    {
        $errors = null;
        set_error_handler(function ($_, $msg, $file, $line) use (&$errors) {
            $errors[] = [
                'message' => $msg,
                'file'    => $file,
                'line'    => $line
            ];
            return true;
        });

        $resource = $callback();
        restore_error_handler();

        if (!$resource) {
            $message = 'Error creating resource: ';
            foreach ($errors as $err) {
                foreach ($err as $key => $value) {
                    $message .= "[$key] $value" . PHP_EOL;
                }
            }
            throw new \RuntimeException(trim($message));
        }

        return $resource;
    }
569032
public static function memoize(callable $provider)
    {
        return function () use ($provider) {
            static $result;
            static $isConstant;

            // Constant credentials will be returned constantly.
            if ($isConstant) {
                return $result;
            }

            // Create the initial promise that will be used as the cached value
            // until it expires.
            if (null === $result) {
                $result = $provider();
            }

            // Return credentials that could expire and refresh when needed.
            return $result
                ->then(function (CredentialsInterface $creds) use ($provider, &$isConstant, &$result) {
                    // Determine if these are constant credentials.
                    if (!$creds->getExpiration()) {
                        $isConstant = true;
                        return $creds;
                    }

                    // Refresh expired credentials.
                    if (!$creds->isExpired()) {
                        return $creds;
                    }
                    // Refresh the result and forward the promise.
                    return $result = $provider();
                })
                ->otherwise(function($reason) use (&$result) {
                    // Cleanup rejected promise.
                    $result = null;
                    return new Promise\RejectedPromise($reason);
                });
        };
    }
773927
public function cache($key, callable $cachedCallable, $ttl, callable $onNoStaleCacheCallable = null)
    {
        $value = $this->getValue($key);

        if ($value->hasResult() && !$value->isStale()) {
            return $value->getResult();
        }

        if (!($ttl instanceof Ttl)) {
            $ttl = new Ttl($ttl);
        }

        $lock_acquired = $this->lockManager->acquire($key, $ttl->getLockTtl());

        if (!$lock_acquired) {
            if ($value->hasResult()) { // serve stale if present
                return $value->getResult();
            }

            if (!$onNoStaleCacheCallable) {
                $onNoStaleCacheCallable = $this->onNoStaleCacheCallable;
            }

            if ($onNoStaleCacheCallable !== null) {
                $event = new NoStaleCacheEvent($this, $key, $cachedCallable, $ttl);

                call_user_func($onNoStaleCacheCallable, $event);

                if ($event->hasResult()) {
                    return $event->getResult();
                }
            }
        }

        $result = call_user_func($cachedCallable);

        $this->setResult($key, $result, $ttl);

        if ($lock_acquired) {
            $this->lockManager->release($key);
        }

        return $result;
    }
443796
public function getCache($cache)
    {
        $cache = self::encodeCache($cache);
        $url = "projects/{$this->project_id}/caches/$cache";
        $this->setJsonHeaders();
        return self::json_decode($this->apiCall(self::GET, $url));
    }
1144985
protected function getRequiredType(callable $callback)
	{
		$ref = new \ReflectionFunction($callback);
		
		if($ref->getNumberOfParameters() > 0)
		{
			$params = $ref->getParameters();
			
			if(isset($params[0]) &&  NULL !== ($type = $params[0]->getClass()))
			{
				return $type;
			}
		}
	}
806153
public function getOnce($key, Closure $callback)
    {
        if ($this->has($key)) {
            return $this->cookies[$key];
        } else {
            $value = $callback();
            $this->set($key, $value);

            return $value;
        }
    }
1217241
public static function factory($driver)
	{
		if (isset(static::$registrar[$driver]))
		{
			$resolver = static::$registrar[$driver];

			return $resolver();
		}

		switch ($driver)
		{
			case 'apc':
				return new Session\Drivers\APC(Cache::driver('apc'));

			case 'cookie':
				return new Session\Drivers\Cookie;

			case 'database':
				return new Session\Drivers\Database(Database::connection());

			case 'file':
				return new Session\Drivers\File(path('storage').'sessions'.DS);

			case 'memcached':
				return new Session\Drivers\Memcached(Cache::driver('memcached'));

			case 'memory':
				return new Session\Drivers\Memory;

			case 'redis':
				return new Session\Drivers\Redis(Cache::driver('redis'));

			default:
				throw new \Exception("Session driver [$driver] is not supported.");
		}
	}
896372
public function extend($driver, Closure $callback)
    {
        $this->factory->extend($driver, $callback);

        return $this;
    }
1115302
public static function make(\Closure $callback = null)
    {
        self::$instance = new static();

        if ($callback instanceof \Closure) {
            return $callback(self::$instance);
        }

        return self::$instance;
    }
732274
public function validateCacheHandler($driver, $handler)
    {
        $store = $handler->getCache()->getStore();
        return static::$expectedStores[$driver] !== get_class($store);
    }
1170237
protected function templateCacheSetup($templateCache) {
    $cacheDir = $templateCache;
    if ($templateCache === null) {
      $cacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "jcalderonzumba" . DIRECTORY_SEPARATOR . "phantomjs";
      if (!file_exists($cacheDir)) {
        mkdir($cacheDir, 0777, true);
      }
    }

    if (!file_exists($cacheDir)) {
      throw new DriverException("Template cache $cacheDir directory does not exist");
    }
    return $cacheDir;
  }
193194
protected function createDriver($driver)
    {
        // We'll check to see if a creator method exists for the given driver. If not we
        // will check for a custom driver creator, which allows developers to create
        // drivers using their own customized driver creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver);
        } else {
            $method = 'create'.Stringy::create($driver)->upperCamelize().'Driver';

            if (method_exists($this, $method)) {
                return $this->$method();
            }
        }
        throw new InvalidArgumentException("Driver [$driver] not supported.");
    }