# `Laev.SessionCache`
[🔗](https://github.com/alexdont/laev/blob/main/lib/laev/session_cache.ex#L1)

What laev remembers for the length of one run, and for how long.

Answers from TMDB about a show that is still airing are true when asked and
wrong later: a session left open for a week is still holding last week's
idea of how many episodes exist. Everything here therefore carries an age,
and goes back to the source once it is past it.

Two rules, both learned from the same bug:

  * **Nothing is remembered.** A lookup that came back empty — no count, no
    next episode — is exactly the answer that changes when an episode drops,
    so it is never cached. Asking again costs one request; being wrong costs
    the user the episode they sat down to watch.
  * **Identity is not news.** Things that cannot change (a title's MyAnimeList
    id) don't belong here; cache those outright.

Per-process, like the process dictionary it is built on: each laev run has
its own, and nothing survives the exit.

And per *scope* within that process, because a process is not always one
person: a server looping over accounts, or answering two of them in turn,
would otherwise hand the second one the first one's answers — which it did,
the first time this was tried, and the symptom was a watchlist count of five
where it should have read twenty-seven.

# `fetch`

The cached value for `key`, or `fun.()` when there is none or it has aged
past `ttl_s` seconds. `nil` results are returned but never stored.

# `forget`

Drop a key, so the next `fetch/3` goes back to the source.

# `get`

The cached value for `key` if it is younger than `ttl_s`, else nil.

# `put`

Remember `value` under `key`, starting its clock now. Returns it.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
