Documentation
¶
Index ¶
- func NewCache(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- func NewCacheByRequestPath(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- func NewCacheByRequestURI(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- func NewCacheByRequestURIWithIgnoreQueryOrder(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) app.HandlerFunc
- type BeforeReplyWithCacheCallback
- type GetCacheStrategyByRequest
- 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 NewCacheByRequestPath ¶
func NewCacheByRequestPath(defaultCacheStore persist.CacheStore, defaultExpire 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(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, opts ...Option) app.HandlerFunc
NewCacheByRequestURI a shortcut function for caching response by uri
func NewCacheByRequestURIWithIgnoreQueryOrder ¶
func NewCacheByRequestURIWithIgnoreQueryOrder(defaultCacheStore persist.CacheStore, defaultExpire 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 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 OnHitCacheCallback ¶
type OnHitCacheCallback app.HandlerFunc
OnHitCacheCallback define the callback when use cache
type OnMissCacheCallback ¶
type OnMissCacheCallback app.HandlerFunc
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