Caching and an API budget (Weather App)

Real APIs are slow and limited. Lines API <city <json register what the API would answer. GET <city <minute asks for a city at a time: if a cached answer is younger than TTL minutes (default 10) print cache hit (<age min old); otherwise fetch it (fetched <city (call <n)) and cache it. BUDGET <n caps the number of calls: when spent, serve a stale cached answer (api budget used up, serving stale (<age min old)) or print error: api budget used up. Unknown cities: error: unknown city <city. After the cache line print the weather line as in stage 4. City names ignore case.

Input: Settings, API lines and GET lines.

Output: Cache / fetch lines followed by the weather.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Cache entries need the time they were fetched.

More Weather App practice