Skip to content

FEATURE:Implement In-Memory Weather Response Caching for the /weather Endpoint . #245

Description

@AYUSH-P-SINGH

Feature Summary

Add in-memory caching for weather API responses to reduce redundant OpenWeatherMap requests and improve response time.

Problem Statement

Currently, every request to the /weather endpoint triggers fresh OpenWeatherMap API calls, even when the same location is queried repeatedly within a short period. This increases response latency and unnecessary API usage.

Proposed Solution

Implement an in-memory caching mechanism in backend/alertsystem.py that:

  • Stores weather responses using a location-based cache key (city:state:country).
  • Checks the cache before making external API requests.
  • Returns cached data when available and not expired.
  • Refreshes the cache after a configurable duration (e.g., 10 minutes).
  • Logs cache hits and cache misses for debugging.

Use Case

This feature improves backend performance by reducing duplicate API requests for frequently searched locations. Users receive faster responses while reducing external API usage and the risk of rate limiting.

Scope of Contribution

Backend
API

Checklist

I have checked existing issues before creating this request
I would like to work on this feature
I am a SsoC 2026 contributor

Additional Context

File to modify:

backend/alertsystem.py`

Acceptance Criteria:

  • Cache responses for repeated location requests.
  • Cache entries expire automatically after the configured duration.
  • Existing API response format remains unchanged.
  • Backend logs indicate cache hits and cache misses.
  • No frontend changes required.

Metadata

Metadata

Assignees

Labels

featureAdd new feature

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions