Comment

Comment by adamtulinius

Your code should be written this way instead:

    if !cache.contains(key) {
      v = db.query("..")
      expiry = calcexpiry(v)
      cache.put(k, v, expiry)
    }
    
    return cache.get(k)
Only one return, and everything is still in the logical order.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton