cacheKey($path, $expiresInMinutes), now()->addSeconds($cacheTtlInSeconds), function () use ($path, $expiresInMinutes): array { $expiresAt = now()->addMinutes($expiresInMinutes); return [ 'temporary_url' => Storage::disk('s3')->temporaryUrl( $path, $expiresAt, [ 'ResponseCacheControl' => 'private, max-age='.($expiresInMinutes * 60), ], ), 'temporary_url_expires_at' => $expiresAt->toIso8601String(), ]; }, ); } public function forget(string $path, int $expiresInMinutes = 10): void { Cache::forget($this->cacheKey($path, $expiresInMinutes)); } protected function cacheKey(string $path, int $expiresInMinutes): string { return sprintf( 's3:temporary-url:%s:%d', hash('sha256', $path), $expiresInMinutes, ); } }