Weather Caching
Weather Cache Schema
Database
- File:
weather_cache.db - Engine:
expo-sqlite - Journal mode:
WAL
Table: forecast_points
| Column | Type | Null | Notes |
|---|---|---|---|
cell_id | TEXT | NOT NULL | Spatial cache bucket key from lat/lon. |
forecast_time | TEXT | NOT NULL | Canonical UTC hour key (toHourKey(...)). |
valid_to | INTEGER | NOT NULL | Expiration timestamp in epoch milliseconds. |
payload | TEXT | NOT NULL | JSON-serialized WeatherPoint. |
last_accessed | INTEGER | NOT NULL | Epoch milliseconds for LRU eviction. |
Primary key:
PRIMARY KEY (cell_id, forecast_time)
Data Invariants
forecast_timeis normalized bytoHourKey(...)for both reads and writes.payloadmust decode toWeatherPoint(time,temp,rh,wspd,sky).- Stale rows are rows where
Date.now() >= valid_to.
Access Patterns
- Exact lookup:
getForecastPoint(cellId, forecastTime). - Same-hour candidates:
getForecastPointsForHour(forecastTime). - Upsert writes:
putForecastPoints(cellId, points, validTo). - LRU eviction:
evictLRU(maxRows). - Exact-hit access update:
getForecastPoint(...)updateslast_accessedafter payload validation. - Access-time touch for fallback hits:
touchForecastPointAccess(cellId, forecastTime).
Cleanup Behavior
- Malformed
payloadrows are removed on read attempts (best effort). - Nearby-fallback access-time touch failures do not block returning usable weather.