Cache and Refresh
Remote discovery and OpenAPI fetches go through pkg/cache.
Storage format
Each cached item is stored as two files keyed by a SHA-256 digest of the cache key:
<digest>.jsonfor metadata<digest>.bodyfor the response body
The metadata captures:
- request URL and method
- headers
ETagLast-ModifiedCache-Control- cache timestamps and expiry
- response status code
- stale marker
Cache key rules
The default key is:
<METHOD>:<URL>
If the request has an Accept header, it becomes:
<METHOD>:<URL>:<Accept>
That matters for API catalogs, which request application/linkset+json.
Fetch lifecycle
The fetcher behaves like this:
- try cache load
- if
manualOnlyand a cached entry exists, use cache - if cached entry is still fresh, use cache
- otherwise send a conditional request if validators exist
- on
304, refresh metadata and reuse the body - on
2xx, replace cache with the new response - on error with cached data and stale-on-error enabled, return stale cache
- otherwise return an error
Corrupt cache handling
If metadata or body files are inconsistent, the store treats the entry as corrupt and deletes it. The next successful fetch recreates the entry.
Refresh endpoint
Use refresh when you want to force revalidation or a fresh network read:
curl -s 'http://127.0.0.1:8765/v1/refresh?config=/work/demo/.cli.json' | jq
Refresh sets ForceRefresh=true, which skips the normal fresh-cache shortcut.
Operational nuance
- stale fallback is enabled by the catalog builder for source fetches
manualOnlyonly prevents network traffic when a cached entry already exists- cache files are not compressed
- metadata and body are written atomically but separately