class BBS::Cache

A thread-safe in-memory cache of computed values, for the answers of a slow service: each value lives ttl seconds, the least recently used go first when the cache is full, and one computation runs per key at a time.

ARTICLES = BBS::Cache.new(ttl: 600, max_entries: 500, max_bytes: 8 * 1024 * 1024)
ARTICLES.fetch([lang, title]) { BBS::HTTP.get(url).body }

Callers that miss the same key at once wait for the one computation and share its value (or its error). When the computation raises and an expired value of the key is still kept, that value is served instead.