Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheExpirationTime ¶
Parse "Cache-Control" header. Return unix seconds time at which item expires. Return 0 for not-cacheable.
func NewCacheTransport ¶
func NewCacheTransport(cachePath string) (rt http.RoundTripper, err error)
Return a net/http RoundTripper transport which caches GETs to local storage. If cachePath is "", returns http.DefaultTransport and no caching is done.
Types ¶
type HttpCache ¶
type HttpCache struct { // UnderlyingTransport defaults to http.DefaultTransport UnderlyingTransport http.RoundTripper // Maximum number of body bytes that will be saved to cache. // Defaults to 1000000. // Body gets read into RAM in its entirety whatever the size. // Larger things pass through but are not written to cache. MaxBodyBytes int // contains filtered or unexported fields }
Implement net/http RoundTripper; store GET results to local storage.
There's no maximum size of total cached stuff or LRU replacement. Everything is cached until it expires. This is simple and mostly useful for static-ish API objects? (Originally developed to hold some keys in an oauth process where the keys changed on a days-to-weeks rate.)
TODO: max total size; LRU replacement (OR, closest-to-expiration replacement)
type StoredResponse ¶
type StoredResponse struct { Status string `json:"S"` // "200 OK" StatusCode int `json:"s"` // 200 Proto string `json:"p"` // "HTTP/1.0" ProtoMajor int `json:"P"` // 1 ProtoMinor int `json:"r"` // 0 Headers map[string][]string `json:"h,omitempty"` Body string `json:"b"` TransferEncoding []string `json:"t,omitempty"` Trailers map[string][]string `json:"z,omitempty"` }
database values are [varint expiration unix time seconds][json StoredResponse]