Documentation
¶
Index ¶
- type Adapter
- type Client
- func (c *Client) Exists(uri string) bool
- func (c *Client) GeneratePrefixAndKey(r *http.Request) (prefix, key string)
- func (c *Client) Middleware(next http.Handler) http.Handler
- func (c *Client) PutItemToCache(next http.Handler, r *http.Request, prefix, key string) (result *http.Response, value []byte)
- func (c *Client) Release(uri string)
- func (c *Client) ReleaseIfStartsWith(uri string)
- func (c *Client) ReleaseURI(uri string)
- type ClientOption
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
// Get retrieves the cached response by a given key. It also
// returns true or false, whether it exists or not.
Get(prefix, key string) ([]byte, bool)
Exists(prefix, key string) bool
Set(prefix, key string, response []byte)
// Release frees cache for a given key.
Release(prefix, key string)
ReleasePrefix(prefix string)
ReleaseIfStartsWith(key string)
}
Adapter interface for HTTP cache middleware client.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client data structure for HTTP cache middleware.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient initializes the cache HTTP middleware client with the given options.
func (*Client) GeneratePrefixAndKey ¶
GeneratePrefixAndKey ...
func (*Client) Middleware ¶
Middleware is the HTTP cache middleware handler.
func (*Client) PutItemToCache ¶
func (c *Client) PutItemToCache(next http.Handler, r *http.Request, prefix, key string) (result *http.Response, value []byte)
PutItemToCache ...
func (*Client) ReleaseIfStartsWith ¶
ReleaseIfStartsWith ...
type ClientOption ¶
ClientOption is used to set Client settings.
func ClientWithAdapter ¶
func ClientWithAdapter(a Adapter) ClientOption
ClientWithAdapter sets the adapter type for the HTTP cache middleware client.
func ClientWithRefreshKey ¶
func ClientWithRefreshKey(refreshKey string) ClientOption
ClientWithRefreshKey sets the parameter key used to free a request cached response. Optional setting.
func ClientWithTTL ¶
func ClientWithTTL(ttl time.Duration) ClientOption
ClientWithTTL sets how long each response is going to be cached.
type Response ¶
type Response struct {
// Value is the cached response value.
Value []byte
// Header is the cached response header.
Header http.Header
// Expiration is the cached response expiration date.
Expiration time.Time
// LastAccess is the last date a cached response was accessed.
// Used by LRU and MRU algorithms.
LastAccess time.Time
// Frequency is the count of times a cached response is accessed.
// Used for LFU and MFU algorithms.
Frequency int
CachedAt time.Time
}
Response is the cached response data structure.
func BytesToResponse ¶
BytesToResponse converts bytes array into Response data structure.