Skip to content

Implement In-Memory Weather Response Caching for /weather Endpoint#246

Open
AYUSH-P-SINGH wants to merge 1 commit into
thetechguardians:mainfrom
AYUSH-P-SINGH:feature/weather-response-caching
Open

Implement In-Memory Weather Response Caching for /weather Endpoint#246
AYUSH-P-SINGH wants to merge 1 commit into
thetechguardians:mainfrom
AYUSH-P-SINGH:feature/weather-response-caching

Conversation

@AYUSH-P-SINGH

Copy link
Copy Markdown

closes issue 245

Description

Overview

This PR introduces an in-memory caching mechanism for weather responses in the /weather endpoint to reduce redundant OpenWeatherMap API calls and improve response times.

Changes Made

  • Added a global weather cache store.
  • Added configurable cache expiration (CACHE_DURATION = 600 seconds).
  • Generated unique cache keys using city, state, and country.
  • Implemented cache lookup before external API requests.
  • Returned cached responses when available and valid.
  • Stored newly generated weather responses in cache.
  • Added cache hit/miss logging for debugging and verification.

Example Flow

Before

Request
  ↓
Geocoding API
  ↓
Weather API
  ↓
Forecast API
  ↓
Response

After

Request
  ↓
Cache Check
  ↓
Cache Hit → Return Cached Response

OR

Cache Miss
  ↓
Geocoding API
  ↓
Weather API
  ↓
Forecast API
  ↓
Store in Cache
  ↓
Response

Benefits

  • Faster response times for repeated searches.
  • Reduced external API usage.
  • Lower risk of rate limiting.
  • Improved backend efficiency.
  • No changes required to the frontend.

Files Modified

backend/alertsystem.py

Type of Change

Feature
Backend Enhancement
Performance Optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant