diff --git a/src/App/Formatter/Media.php b/src/App/Formatter/Media.php index 6620f99f4a..07d5d723e0 100644 --- a/src/App/Formatter/Media.php +++ b/src/App/Formatter/Media.php @@ -14,9 +14,13 @@ use Ushahidi\Core\Entity; use Ushahidi\Core\Traits\FormatterAuthorizerMetadata; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Cache; class Media extends API { + // This is rather long, because what we cache here rarely (if ever) changes + const CACHE_LIFETIME = 24 * 3600 ; # in seconds + use FormatterAuthorizerMetadata; protected function addMetadata(array $data, Entity $media) @@ -60,6 +64,17 @@ protected function formatOFilename($value) array_push($url_path, $filename); $path = implode("/", $url_path); + return Cache::remember( + 'Ushahidi\App\Formatter\Media.publicUrl[' . $path . ']', + self::CACHE_LIFETIME, + function () use ($path) { + return $this->getStorageObjectPublicUrl($path); + } + ); + } + + protected function getStorageObjectPublicUrl(string $path) : string + { $adapter = Storage::getAdapter(); // Special handling for RS to get SSL URLs if ($adapter instanceof \League\Flysystem\Rackspace\RackspaceAdapter) {