Documentation
¶
Index ¶
- func NewCache(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- func NewCacheByKeyStrategy(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- func NewCacheByRequestPath(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
- func NewCacheByRequestURI(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
- func NewCacheByRequestURIWithIgnoreQueryOrder(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
- type BeforeReplyWithCacheCallback
- type ByPath
- type ByURI
- type ByURIWithIgnoreQueryOrder
- type GetCacheStrategyByRequest
- type KeyStrategy
- type OnHitCacheCallback
- type OnMissCacheCallback
- type OnShareSingleFlightCallback
- type Option
- func WithBeforeReplyWithCache(cb BeforeReplyWithCacheCallback) Option
- func WithCacheStrategyByRequest(getGetCacheStrategyByRequest GetCacheStrategyByRequest) Option
- func WithOnHitCache(cb OnHitCacheCallback) Option
- func WithOnMissCache(cb OnMissCacheCallback) Option
- func WithOnShareSingleFlight(cb OnShareSingleFlightCallback) Option
- func WithPrefixKey(prefix string) Option
- func WithSingleFlightForgetTimeout(forgetTimeout time.Duration) Option
- func WithoutHeader(b bool) Option
- type Options
- type ResponseCache
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCache ¶
func NewCache( defaultCacheStore persist.CacheStore, defaultExpire time.Duration, opts ...Option, ) app.HandlerFunc
NewCache user must pass getCacheKey to describe the way to generate cache key
func NewCacheByKeyStrategy ¶
func NewCacheByKeyStrategy(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, strategy KeyStrategy, opts ...Option) app.HandlerFunc
NewCacheByKeyStrategy is a shortcut function for caching responses based on configurable key generation strategies.
func NewCacheByRequestPath ¶
func NewCacheByRequestPath(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
NewCacheByRequestPath a shortcut function for caching response by url path, means will discard the query params.
func NewCacheByRequestURI ¶
func NewCacheByRequestURI(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
NewCacheByRequestURI a shortcut function for caching response by uri.
func NewCacheByRequestURIWithIgnoreQueryOrder ¶
func NewCacheByRequestURIWithIgnoreQueryOrder(store persist.CacheStore, duration time.Duration, opts ...Option) app.HandlerFunc
NewCacheByRequestURIWithIgnoreQueryOrder a shortcut function for caching response by uri and ignore query param order.
Types ¶
type BeforeReplyWithCacheCallback ¶
type BeforeReplyWithCacheCallback func(c *app.RequestContext, cache *ResponseCache)
type ByPath ¶
type ByPath struct{}
ByPath implements KeyStrategy using the request path.
func (*ByPath) GenerateKey ¶
func (s *ByPath) GenerateKey(c *app.RequestContext) (string, error)
type ByURI ¶
type ByURI struct{}
ByURI implements KeyStrategy using the request URI.
func (*ByURI) GenerateKey ¶
func (s *ByURI) GenerateKey(c *app.RequestContext) (string, error)
type ByURIWithIgnoreQueryOrder ¶
type ByURIWithIgnoreQueryOrder struct{}
ByURIWithIgnoreQueryOrder implements KeyStrategy using the request URI with ordered query parameters.
func (*ByURIWithIgnoreQueryOrder) GenerateKey ¶
func (s *ByURIWithIgnoreQueryOrder) GenerateKey(c *app.RequestContext) (string, error)
type GetCacheStrategyByRequest ¶
GetCacheStrategyByRequest User can use this function to design custom cache strategy by request. The first return value bool means whether this request should be cached. The second return value Strategy determine the special strategy by this request.
type KeyStrategy ¶
type KeyStrategy interface {
GenerateKey(c *app.RequestContext) (string, error)
}
KeyStrategy defines the interface for cache key generation strategies.
type OnHitCacheCallback ¶
type OnHitCacheCallback func(ctx context.Context, c *app.RequestContext)
OnHitCacheCallback define the callback when use cache
type OnMissCacheCallback ¶
type OnMissCacheCallback func(ctx context.Context, c *app.RequestContext)
OnMissCacheCallback define the callback when use cache
type OnShareSingleFlightCallback ¶
type OnShareSingleFlightCallback func(ctx context.Context, c *app.RequestContext)
OnShareSingleFlightCallback define the callback when share the singleFlight result
type Option ¶
type Option struct {
F func(o *Options)
}
Option represents the optional function.
func WithBeforeReplyWithCache ¶
func WithBeforeReplyWithCache(cb BeforeReplyWithCacheCallback) Option
WithBeforeReplyWithCache will be called before replying with cache.
func WithCacheStrategyByRequest ¶
func WithCacheStrategyByRequest(getGetCacheStrategyByRequest GetCacheStrategyByRequest) Option
WithCacheStrategyByRequest set up the custom strategy by per request
func WithOnHitCache ¶
func WithOnHitCache(cb OnHitCacheCallback) Option
WithOnHitCache will be called when cache hit.
func WithOnMissCache ¶
func WithOnMissCache(cb OnMissCacheCallback) Option
WithOnMissCache will be called when cache miss.
func WithOnShareSingleFlight ¶
func WithOnShareSingleFlight(cb OnShareSingleFlightCallback) Option
WithOnShareSingleFlight will be called when share the singleflight result
func WithSingleFlightForgetTimeout ¶
WithSingleFlightForgetTimeout to reduce the impact of long tail requests. singleFlight.Forget will be called after the timeout has reached for each backend request when timeout is greater than zero.
func WithoutHeader ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options contains all options
type ResponseCache ¶
ResponseCache record the http response cache