Documentation ¶
Overview ¶
Package httpcache implements net/http RoundTripper with caching. Persistent with a cache using files. Volatile with a cache in memory.
The following rules applies for caching:
- only responses of GET requests are cached (no POST, etc.)
- only body response is cached (no headers)
- only response status 200 (OK) and response status 301 (Moved Permanently)
Index ¶
- func NewPersistent(transport http.RoundTripper, path string, TTL time.Duration) http.RoundTripper
- func NewPersistentClient(path string, TTL time.Duration) (*http.Client, error)
- func NewVolatile(transport http.RoundTripper, TTL time.Duration, maxItems int) http.RoundTripper
- func NewVolatileClient(TTL time.Duration, maxItems int) *http.Client
- type Cache
- type CachedRoundTrip
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPersistent ¶
func NewPersistent(transport http.RoundTripper, path string, TTL time.Duration) http.RoundTripper
NewPersistent creates an http RoundTripper with a file cache. Cache files will be created under path.
func NewPersistentClient ¶
NewPersistentClient creates an http client with a file cache.
func NewVolatile ¶
func NewVolatile(transport http.RoundTripper, TTL time.Duration, maxItems int) http.RoundTripper
NewVolatile creates an http RoundTripper with a memory cache.
Types ¶
type CachedRoundTrip ¶
type CachedRoundTrip struct { Transport http.RoundTripper Cache Cache TTL time.Duration }
A CachedRoundTrip implements net/http RoundTripper with a cache.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
persistent
Binary persistent demonstrates using a persistent (with files) httpcache.
|
Binary persistent demonstrates using a persistent (with files) httpcache. |
volatile
Binary volatile demonstrates using a volatile (in memory) httpcache.
|
Binary volatile demonstrates using a volatile (in memory) httpcache. |
Click to show internal directories.
Click to hide internal directories.