Rinvex\Repository\Traits\Cacheable::cacheCallback PHP Method

cacheCallback() protected method

Cache given callback.
protected cacheCallback ( string $class, string $method, array $args, Closure $closure ) : mixed
$class string
$method string
$args array
$closure Closure
return mixed
    protected function cacheCallback($class, $method, $args, Closure $closure)
    {
        $repositoryId = $this->getRepositoryId();
        $lifetime = $this->getCacheLifetime();
        $hash = $this->generateCacheHash($args);
        $cacheKey = $class . '@' . $method . '.' . $hash;
        // Switch cache driver on runtime
        if ($driver = $this->getCacheDriver()) {
            $this->getContainer('cache')->setDefaultDriver($driver);
        }
        // We need cache tags, check if default driver supports it
        if (method_exists($this->getContainer('cache')->getStore(), 'tags')) {
            $result = $lifetime === -1 ? $this->getContainer('cache')->tags($repositoryId)->rememberForever($cacheKey, $closure) : $this->getContainer('cache')->tags($repositoryId)->remember($cacheKey, $lifetime, $closure);
            // We're done, let's clean up!
            $this->resetRepository();
            return $result;
        }
        // Default cache driver doesn't support tags, let's do it manually
        $this->storeCacheKeys($class, $method, $hash);
        $result = $lifetime === -1 ? $this->getContainer('cache')->rememberForever($cacheKey, $closure) : $this->getContainer('cache')->remember($cacheKey, $lifetime, $closure);
        // We're done, let's clean up!
        $this->resetCachedRepository();
        return $result;
    }