# Cache checks

> Serve allowed checks from memory for up to 30 seconds, cleared within 100 milliseconds of a revocation.

From `sdk/README.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/sdk/cache.

Every `check` calls the server by default, so a revocation applies to the next request. A long-running process can cache allowed answers instead:

```ts
const auth = createTensile({ url, appKey, cache: true })
```

The cache follows the server's own cache rules:

- It holds `GET /v1/events/stream` open, and serves nothing until the stream sends `ready`.
- Each `invalidate` event clears it, so a revocation reaches it within 100 milliseconds. The stream carries no session hashes, so every change clears everything.
- When the stream ends, fails, or stays silent for 45 seconds, it serves nothing until the next `ready`. It reconnects after 1 second, backing off to 30.
- It holds only allowed answers that set no cookie, for at most 30 seconds and never past the session's expiry, keyed by the SHA-256 of the credential and the facts the answer depends on.
- It never caches a DPoP request, an approval, or a need with `within` or `assurance`.

Set `cache: { ttlMs, maxEntries }` to hold answers for less time or hold fewer of them. `auth.cache.active` and `auth.cache.size` report its state, and `auth.close()` stops the stream. Leave it off on serverless runtimes, which can't hold a stream.
