cache package - github.com/chenyahui/gin-cache - Go Packages
- func Cache(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) gin.HandlerFunc
- func CacheByRequestPath(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) gin.HandlerFunc
- func CacheByRequestURI(defaultCacheStore persist.CacheStore, defaultExpire time.Duration, ...) gin.HandlerFunc
- func CorsHeaders() []string
- type BeforeReplyWithCacheCallback
- type Config
- type Discard
- type GetCacheStrategyByRequest
- type Logger
- type OnHitCacheCallback
- type OnMissCacheCallback
- type OnShareSingleFlightCallback
- type Option
- func IgnoreQueryOrder() Option
- func WithBeforeReplyWithCache(cb BeforeReplyWithCacheCallback) Option
- func WithCacheStrategyByRequest(getGetCacheStrategyByRequest GetCacheStrategyByRequest) Option
- func WithDiscardHeaders(headers []string) Option
- func WithLogger(l Logger) 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() Option
- type ResponseCache
- type Strategy
This section is empty.
This section is empty.
Cache user must pass getCacheKey to describe the way to generate cache key
CacheByRequestPath a shortcut function for caching response by url path, means will discard the query params
CacheByRequestURI a shortcut function for caching response by uri
type BeforeReplyWithCacheCallback func(c *gin.Context, cache *ResponseCache)
Config contains all options
Discard the default logger that will discard all logs of gin-cache
GetCacheStrategyByRequest User can 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 Logger interface {
Errorf(string, ...interface{})
}
Logger define the logger interface
OnHitCacheCallback define the callback when use cache
OnMissCacheCallback define the callback when use cache
OnShareSingleFlightCallback define the callback when share the singleflight result
type Option func(c *Config)
Option represents the optional function.
func IgnoreQueryOrder() Option
IgnoreQueryOrder will ignore the queries order in url when generate cache key . This option only takes effect in CacheByRequestURI function
func WithBeforeReplyWithCache(cb BeforeReplyWithCacheCallback) Option
WithBeforeReplyWithCache will be called before replying with cache.
func WithCacheStrategyByRequest(getGetCacheStrategyByRequest GetCacheStrategyByRequest) Option
WithCacheStrategyByRequest set up the custom strategy by per request
func WithOnHitCache(cb OnHitCacheCallback) Option
WithOnHitCache will be called when cache hit.
func WithOnMissCache(cb OnMissCacheCallback) Option
WithOnMissCache will be called when cache miss.
func WithOnShareSingleFlight(cb OnShareSingleFlightCallback) Option
WithOnShareSingleFlight will be called when share the singleflight result
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() Option
Strategy the cache strategy