Documentation ¶
Index ¶
- Variables
- func Cache(opts ...Option) gin.HandlerFunc
- func CacheByRequestPath(opts ...Option) gin.HandlerFunc
- func CacheByRequestURI(opts ...Option) gin.HandlerFunc
- func CacheKeyWithPrefix(prefix, key string) string
- func GenerateCacheKeyByPath(c *gin.Context) (string, bool)
- func GenerateCacheKeyByURI(c *gin.Context) (string, bool)
- type Discard
- type Encoding
- type GenerateCacheKey
- type JSONEncoding
- type JSONGzipEncoding
- type Logger
- type OnHitCacheCallback
- type OnShareSingleFlightCallback
- type Option
- func WithCacheStore(store persist.CacheStore) Option
- func WithEncoding(encode Encoding) Option
- func WithExpire(expire time.Duration) Option
- func WithGenerateCacheKey(f GenerateCacheKey) Option
- func WithHandle(handle gin.HandlerFunc) Option
- func WithLogger(l Logger) Option
- func WithOnHitCache(cb OnHitCacheCallback) Option
- func WithOnShareSingleFlight(cb OnShareSingleFlightCallback) Option
- func WithPool(pool Pool) Option
- func WithRand(rand Rand) Option
- func WithSingleFlightForgetTimeout(forgetTimeout time.Duration) Option
- func WithSingleflight(group *singleflight.Group) Option
- type Options
- type Pool
- type Rand
- type ResponseCache
Constants ¶
This section is empty.
Variables ¶
var PageCachePrefix = "wcache.page.cache:"
PageCachePrefix default page cache key prefix
Functions ¶
func Cache ¶
func Cache(opts ...Option) gin.HandlerFunc
Cache user must pass getCacheKey to describe the way to generate cache key
func CacheByRequestPath ¶
func CacheByRequestPath(opts ...Option) gin.HandlerFunc
CacheByRequestPath a shortcut function for caching response by url path, means will discard the query params
func CacheByRequestURI ¶
func CacheByRequestURI(opts ...Option) gin.HandlerFunc
CacheByRequestURI a shortcut function for caching response by uri
func CacheKeyWithPrefix ¶
func GenerateCacheKeyByPath ¶
GenerateCacheKeyByPath generate key with PageCachePrefix and request Path
Types ¶
type Discard ¶
type Discard struct { }
Discard the default logger that will discard all logs of gin-cache
func NewDiscard ¶
func NewDiscard() Discard
NewDiscard a discard logger on which always succeed without doing anything
type Encoding ¶
type Encoding interface { Marshal(v interface{}) ([]byte, error) Unmarshal(data []byte, v interface{}) error }
Encoding interface
type JSONEncoding ¶
type JSONEncoding struct{}
func (JSONEncoding) Marshal ¶
func (JSONEncoding) Marshal(v interface{}) ([]byte, error)
func (JSONEncoding) Unmarshal ¶
func (JSONEncoding) Unmarshal(data []byte, v interface{}) error
type JSONGzipEncoding ¶
type JSONGzipEncoding struct{}
func (JSONGzipEncoding) Marshal ¶
func (JSONGzipEncoding) Marshal(v interface{}) ([]byte, error)
func (JSONGzipEncoding) Unmarshal ¶
func (JSONGzipEncoding) Unmarshal(data []byte, v interface{}) error
type Logger ¶
type Logger interface {
Errorf(string, ...interface{})
}
Logger define the logger interface
type OnHitCacheCallback ¶
OnHitCacheCallback define the callback when use cache
type OnShareSingleFlightCallback ¶
OnShareSingleFlightCallback define the callback when share the singleflight result
type Option ¶
type Option func(c *Options)
Option represents the optional function.
func WithCacheStore ¶
func WithCacheStore(store persist.CacheStore) Option
func WithEncoding ¶
func WithExpire ¶
func WithGenerateCacheKey ¶
func WithGenerateCacheKey(f GenerateCacheKey) Option
func WithHandle ¶
func WithHandle(handle gin.HandlerFunc) Option
func WithOnHitCache ¶
func WithOnHitCache(cb OnHitCacheCallback) Option
WithOnHitCache will be called when cache hit.
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. when request in the singleflight, after the forget timeout, singleflight.Forget will be called
func WithSingleflight ¶
func WithSingleflight(group *singleflight.Group) Option
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options contains all options
type Pool ¶
type Pool interface { Get() *ResponseCache Put(*ResponseCache) }
type ResponseCache ¶
type ResponseCache struct { Status int Header http.Header Data []byte // contains filtered or unexported fields }
func (*ResponseCache) MarshalBinary ¶
func (c *ResponseCache) MarshalBinary() ([]byte, error)
func (*ResponseCache) UnmarshalBinary ¶
func (c *ResponseCache) UnmarshalBinary(data []byte) error