diff --git a/controllers/rateController.js b/controllers/rateController.js index 627ef95..d444fe6 100644 --- a/controllers/rateController.js +++ b/controllers/rateController.js @@ -28,9 +28,16 @@ exports.getLatestRates = async (req, res) => { stale: true // Marked as stale because it wasn't in Redis }; - // Re-populate Redis so the next request is fast - await redisClient.set(CACHE_KEY, JSON.stringify(fallbackPayload)); - + try { + // Re-populate Redis so the next request is fast + await redisClient.set( + CACHE_KEY, JSON.stringify(fallbackPayload), + { EX: 3600 } + ); + } catch (redisError) { + redisError.message = 'Redis cache update failed. Using stale data.'; + logger.error(redisError.message); + } return res.status(200).json(fallbackPayload); }