Aws\Credentials\CredentialProvider::cache PHP Метод

cache() публичный статический Метод

Defaults to using a simple file-based cache when none provided.
public static cache ( callable $provider, Aws\CacheInterface $cache, string | null $cacheKey = null ) : callable
$provider callable Credentials provider function to wrap
$cache Aws\CacheInterface Cache to store credentials
$cacheKey string | null (optional) Cache key to use
Результат callable
    public static function cache(callable $provider, CacheInterface $cache, $cacheKey = null)
    {
        $cacheKey = $cacheKey ?: 'aws_cached_credentials';
        return function () use($provider, $cache, $cacheKey) {
            $found = $cache->get($cacheKey);
            if ($found instanceof CredentialsInterface && !$found->isExpired()) {
                return Promise\promise_for($found);
            }
            return $provider()->then(function (CredentialsInterface $creds) use($cache, $cacheKey) {
                $cache->set($cacheKey, $creds, null === $creds->getExpiration() ? 0 : $creds->getExpiration() - time());
                return $creds;
            });
        };
    }