@earth-app/collegedb
    Preparing search index...

    Function cached

    • Returns a cached value for key, computing and storing it on a miss.

      On a hit the stored value is returned (unless it has expired, in which case the entry is deleted and treated as a miss). A corrupt entry self-heals: it is deleted and the value is recomputed.

      Type Parameters

      • T

        Type of the cached value

      Parameters

      • key: string

        Cache key

      • fetcher: () => Promise<T>

        Async producer invoked on a miss

      • options: CacheOptions = {}

        TTL and KV override

      Returns Promise<T>

      The cached or freshly computed value

      If no KV store is available

      1.2.4

      const user = await cached(`user:${id}`, () => loadUser(id), { ttl: 3600 });