Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct { // Directory where the cache is stored. Defaults to gohttpdisk. Dir string // If true, don't include the request hostname in the path for each element. NoHosts bool }
Cache will cache http.Responses on disk, using the http.Request to calculate a key. It deals with keys and files, not the network.
func (*Cache) Get ¶
Get the cached data for a request. An empty byte array will be returned if the entry doesn't exist or can't be read for any reason.
type CacheKey ¶
a key in the cache
type HTTPDisk ¶
type HTTPDisk struct { // Underlying Cache. Cache Cache // if nil, http.DefaultTransport is used. Transport http.RoundTripper Options Options }
HTTPDisk is a caching http transport.
func NewHTTPDisk ¶
NewHTTPDisk constructs a new HTTPDisk.
type Options ¶
type Options struct { // Directory where the cache is stored. Defaults to httpdisk. Dir string // Maximum amount of time a cached response is considered fresh. If less // than or equal to zero, then all content is considered fresh. If positive, // then cached content will be re-fetched if it is older than this. MaxAge time.Duration // Don't read anything from cache (but still write) Force bool // Don't read errors from cache (but still write) ForceErrors bool // Optional logger Logger *log.Logger // Don't cache errors during background revalidation. Leave stale data in cache instead. // Only relevant if StaleWhileRevalidate is set. NoCacheRevalidationErrors bool // If true, don't include the request hostname in the path for each element. NoHosts bool // If StaleWhileRevalidate is enabled, you may optionally set this wait group // to be notified when background fetches complete. RevalidationWaitGroup *sync.WaitGroup // Return stale cached responses while refreshing the cache in the background. // Only relevant if MaxAge is set. StaleWhileRevalidate bool // Update cache file modification time before kicking off a background revalidation. // Helps guard against thundering herd problem, but risks leaving stale data in the // cache longer than expected. Only relevant if StaleWhileRevalidate is set. TouchBeforeRevalidate bool }
Options for creating a new HTTPDisk.
Click to show internal directories.
Click to hide internal directories.