Documentation
¶
Overview ¶
Package httpcache caches provider responses on disk, so a screen you have already seen is drawn from the last answer while a fresh one is fetched.
It is an http.RoundTripper rather than a decorator around forge.Forge, which means it covers both providers and every endpoint without any call site knowing it exists. The alternative — a caching Forge — would need a hand-written key for each of forty methods, and would silently miss the next one added.
Nothing derived from a credential is ever written. Only response bodies and their validators are stored; the request's Authorization and token headers are neither stored nor part of a cache key. Authentication stays where gu has always kept it: in memory, delegated to the CLIs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOffline = errors.New("not in the cache, and this lookup may not use the network")
ErrOffline is returned for a request that is not in the cache while the context forbids reaching the network.
Functions ¶
func Clear ¶
Clear empties the cache directory. It is what `:cache clear` runs, and what anyone reaching for a fresh start expects to be able to do.
func Dir ¶
Dir is where the cache lives, given gu's config directory as a fallback for systems with no user cache directory of their own.
Types ¶
type Transport ¶
type Transport struct {
// Base is the round-tripper doing the real work; nil means
// http.DefaultTransport.
Base http.RoundTripper
// Dir is where entries live. An empty Dir disables the cache entirely,
// which is what a configuration that switched it off resolves to.
Dir string
// Scope separates one account's entries from another's. Two profiles
// routinely share a host and see different things there, so the profile
// label is part of every key — it is a name, never a token.
Scope string
// MaxAge bounds how old an entry may be and still be served without asking
// the provider. Beyond it the entry is still a fine revalidation base.
MaxAge time.Duration
}
Transport caches GET responses and revalidates them with If-None-Match.