Documentation ¶
Overview ¶
Package cache implements middleware for response caching. Request's component used as a key.
Index ¶
- func KeyFunc(fn func(r *http.Request) string) func(m *Middleware)
- func KeyWithBody(m *Middleware)
- func KeyWithHeaders(m *Middleware)
- func KeyWithHeadersExcluded(headers ...string) func(m *Middleware)
- func KeyWithHeadersIncluded(headers ...string) func(m *Middleware)
- func Methods(methods ...string) func(m *Middleware)
- type Middleware
- type Service
- type ServiceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KeyFunc ¶
func KeyFunc(fn func(r *http.Request) string) func(m *Middleware)
KeyFunc defines custom caching key function
func KeyWithBody ¶
func KeyWithBody(m *Middleware)
KeyWithBody makes whole body to be a part of the caching key
func KeyWithHeaders ¶
func KeyWithHeaders(m *Middleware)
KeyWithHeaders makes all headers to affect caching key
func KeyWithHeadersExcluded ¶
func KeyWithHeadersExcluded(headers ...string) func(m *Middleware)
KeyWithHeadersExcluded make all headers, except passed in to affect caching key
func KeyWithHeadersIncluded ¶
func KeyWithHeadersIncluded(headers ...string) func(m *Middleware)
KeyWithHeadersIncluded allows some headers to affect caching key
func Methods ¶
func Methods(methods ...string) func(m *Middleware)
Methods sets what HTTP methods allowed to be cached, default is "GET" only
Types ¶
type Middleware ¶
type Middleware struct { Service // contains filtered or unexported fields }
Middleware for caching responses. The key cache generated from request.
func New ¶
func New(svc Service, opts ...func(m *Middleware)) *Middleware
New makes cache middleware for given cache.Service and optional set of params By default allowed methods limited to GET only and key for request's URL
func (*Middleware) Middleware ¶
func (m *Middleware) Middleware(next http.RoundTripper) http.RoundTripper
Middleware is the middleware wrapper injecting external cache.Service (LoadingCache) into the call chain. Key extracted from the request and options defines what part of request should be used for key and what method are allowed for caching.
type Service ¶
Service defines loading cache interface to be used for caching, matching github.com/go-pkgz/lcw interface
type ServiceFunc ¶
ServiceFunc is an adapter to allow the use of an ordinary functions as the loading cache.