JavaScript · Advanced · Ticket 3Ticket #39 · from Hannah Cole, Senior Engineer
  1. Example
  2. Warm-up 1
  3. Warm-up 2
  4. Ticket
Brief
NEW TICKET#39 · Currency conversion

A small cache for exchange rates

Hannah Cole · Senior Engineer
Opened today

“We call the exchange-rate service every time someone views a foreign-currency invoice, and we're hitting its limits. Keep a small cache of the most recently used currencies. When a currency is asked for: if it's cached, that's a hit, and it becomes the most recently used. If not, it's a miss: we fetch it and add it, and if the cache is now over capacity, drop the least recently used currency. To check the policy before we wire it up, cacheLog replays a list of requests and says hit or miss for each.”

YOUR PLAN
  1. 1Watch an example2 min
  2. 2Warm-up 11 min
  3. 3Warm-up 21 min
  4. 4Fix the ticket26 min
BY THE END YOU CAN
  • Use a Map's key order as a recency list
  • Move a key to the end with delete and set
  • Find the oldest key with keys().next()
About 30 minutes
Four short steps. Nothing is timed, and you can leave any time.