remember($cacheKey, $ttlSeconds, function () use ($viewName, $data) { return view($viewName, $data)->render(); }) ); } public static function readAssetInMemory(string $assetFilename, int $ttlSeconds = 10000, $asset_folder = null): ?string { $assetFilename = ltrim($assetFilename, '/\\'); $cacheKey = 'Cache:Assets:Static:' . $assetFilename; if (!$asset_folder) { $filePath = storage_path('app/cache/static/' . $assetFilename); } else { $filePath = $asset_folder . $assetFilename; } $data = Cache::get($cacheKey); if ($data) { return $data['content']; } if (!File::exists($filePath)) { return null; } $fileContent = file_get_contents($filePath); $mimeType = File::mimeType($filePath) ?? 'application/octet-stream'; $data = [ 'content' => $fileContent, 'mime' => $mimeType, ]; Cache::put($cacheKey, $data, $ttlSeconds); return $fileContent; } public static function readPublicAssetInMemory($assetFilename, $ttlSeconds = 10000) { $asset_folder = public_path('static/'); return self::readAssetInMemory($assetFilename, $ttlSeconds, $asset_folder); } public static function getAssetInMemory(string $assetFilename, int $ttlSeconds = 10000) { $assetFilename = ltrim($assetFilename, '/\\'); $cacheKey = 'Cache:Assets:Static:' . $assetFilename; $filePath = storage_path('app/cache/static/' . $assetFilename); $data = Cache::get($cacheKey); if ($data) { return Response::raw($data['content']) ->withHeader('Content-Type', $data['mime'] ?? 'text/css') ->withHeader('Content-Length', (string) strlen($data['content'])) ->withStatus(200); } try { $fileContent = file_get_contents($filePath); $mimeType = File::mimeType($filePath) ?? 'application/octet-stream'; // Cache content + mime type $data = [ 'content' => $fileContent, 'mime' => $mimeType, ]; Cache::put($cacheKey, $data, $ttlSeconds); return Response::raw($data['content']) ->withHeader('Content-Type', $data['mime'] ?? 'text/css') ->withHeader('Content-Length', (string) strlen($data['content'])) ->withStatus(200); } catch (\Throwable $th) { return Response::withStatus(404, 'Not Found ' . $th->getMessage()); } } }