ttl-keyed-json-cache-lenient-decode
Installation
SKILL.md
A keyed cache with an expiry, stored as one JSON blob
Small enough not to deserve a table, big enough that re-resolving on every open is rude. Each entry carries its own fetch time, so expiry is a property of the value rather than of the whole file:
// adapted — names generalized, and the resolution chain condensed: `pickThumbnailUrl` stands in
// for six lines of the source (parse the response, walk its sections, take the *last* thumbnail of
// the first item that has one). The name is invented here; do not read a `first…` into it.
@Serializable
private data class CachedArtwork(val url: String, val cachedAt: Long) {
fun isStale(): Boolean =
Clock.System.now().toEpochMilliseconds() - cachedAt > ARTWORK_CACHE_TTL_MILLIS
}
/** Time-to-live (TTL): how long a resolved entry stays usable before it is fetched again. */
private const val ARTWORK_CACHE_TTL_MILLIS = 7L * 24 * 60 * 60 * 1000
private val cacheJson = Json { ignoreUnknownKeys = true }