Skip to content

weather: cache forecasts and cut redundant loads - #14

Open
dharmapoudel wants to merge 1 commit into
JoeyEamigh:devfrom
dharmapoudel:weather-forecast-cache
Open

dharmapoudel wants to merge 1 commit into
JoeyEamigh:devfrom
dharmapoudel:weather-forecast-cache

Conversation

@dharmapoudel

Copy link
Copy Markdown
Contributor

The weather app refetched open-meteo on every mount, every 15 minutes, and every config write -- flashing "loading weather..." each time and hitting the network even when nothing changed.

What this does

  • Caches the forecast in localStorage for 15 minutes (the refresh cadence), keyed by rounded coords + units. Warm starts paint instantly with no network; driving to a new city or switching metric/imperial refetches. Corrupt or unavailable storage degrades to the old behavior.
  • Background refreshes keep showing the current data instead of flashing "loading". A failed background refresh keeps the stale data instead of swapping to the error screen; the next 15-minute tick retries. (Deliberate behavior change -- happy to revert to error-on-failure if you prefer.)
  • Config-change reloads are filtered to the units/location keys instead of firing on every config write.
  • Concurrent loads are deduped: a config change racing the initial load shares one fetch.

Files

  • packages/webapps/catalog/weather/src/App.tsx -- readForecastCache/writeForecastCache helpers, cache lookup in the load path, in-flight dedupe, key-filtered onChanged.

Validation

  • tsc --noEmit clean, vite build clean.
  • Logic tests for the cache helpers: hit, miss on coords/units change, stale-entry boundary, corrupt JSON, coord rounding, storage-quota failure -- 9/9 pass.
  • Not tested on physical Car Thing hardware.

- Cache the forecast in localStorage for 15 minutes (the refresh
  cadence), keyed by rounded coords + units: warm starts paint
  instantly with no network, and moving to a new city or switching
  units refetches. Corrupt or unavailable storage degrades to the
  old behavior.
- Background refreshes no longer flash "loading" every 15 minutes;
  a failed refresh keeps the stale data instead of swapping to the
  error screen (the next tick retries).
- Only reload on `units`/`location` config changes instead of every
  config write, and dedupe concurrent loads so a config change
  racing the initial load shares one fetch.
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