diff --git a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php index b1edca5..1b76a99 100644 --- a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php +++ b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php @@ -866,8 +866,8 @@ class TelemetryController extends Controller // Set cache key per user $cacheKey = "user_assets_health_{$userId}"; - // Cache for 30 seconds - $formattedData = Cache::remember($cacheKey, now()->addSeconds(value: 30), function () use ($userId) { + // Cache the response for 60 seconds + $formattedData = Cache::remember($cacheKey, now()->addSeconds(value: 60), function () use ($userId) { $assetDeviceListing = UserAssetLink::with('asset.devices') ->where(['user_id' => $userId, 'active' => 1]) ->get(); @@ -1025,7 +1025,8 @@ class TelemetryController extends Controller $token = readHeaderToken(); $cacheKey = "device_indicators_{$token['sub']}_asset_{$assetId}"; - $cachedData = Cache::remember($cacheKey, now()->addSeconds(value: 30), function () use ($token, $assetId) { + // Cache the response for 60 seconds + $cachedData = Cache::remember($cacheKey, now()->addSeconds(value: 60), function () use ($token, $assetId) { $assetDeviceListing = $this->getUserAssetLinkWithDevices($token['sub'], $assetId); return $assetDeviceListing->map(function($link){ @@ -1287,8 +1288,8 @@ class TelemetryController extends Controller ], 404); } - // Cache the response for 1 hour - // $cachedData = Cache::remember($cacheKey, now()->addHours(value: 1), function () use ($deviceId) { + // Cache the response for 60 seconds + $cachedData = Cache::remember($cacheKey, now()->addSeconds(value: 60), function () use ($deviceId) { $deviceParams = $this->getPopupTimeseriesKeys($deviceId); if ($deviceParams->isEmpty()) { @@ -1309,14 +1310,14 @@ class TelemetryController extends Controller // Transform the data using our TelemetryService $transformed = $this->telemetryService->transformTelemetryData($deviceId, $data, $displayNameMap, $deviceLiveStatus['active']); - $response = [ + return [ 'success' => true, 'updated_time' => $transformed['dateTime'] ? $this->telemetryService->convertToUserTimezone($transformed['dateTime']) : null, 'data' => $transformed['telemetry'] ]; - // }); + }); - return response()->json($response); + return response()->json($cachedData); } catch(Exception $e){ Log::error("Error fetching global indicators: " . $e->getMessage(), ['device_id' => $deviceId]);