Documentation ¶
Index ¶
- Variables
- func Cache(store persist.Store, expire time.Duration, handle gin.HandlerFunc, ...) gin.HandlerFunc
- func CacheWithRequestPath(store persist.Store, expire time.Duration, handle gin.HandlerFunc, ...) gin.HandlerFunc
- func CacheWithRequestURI(store persist.Store, expire time.Duration, handle gin.HandlerFunc, ...) gin.HandlerFunc
- func GenerateKeyWithPrefix(prefix, key string) string
- func GenerateRequestPathKey(c *gin.Context) (string, bool)
- func GenerateRequestURIKey(c *gin.Context) (string, bool)
- type BodyCache
- type BodyWriter
- type Config
- type Discard
- type Encoding
- type JSONEncoding
- type JSONGzipEncoding
- type Logger
- type Option
- type Pool
Constants ¶
This section is empty.
Variables ¶
var PageCachePrefix = "gincache.page.cache:"
PageCachePrefix default page cache key prefix
Functions ¶
func Cache ¶
func Cache(store persist.Store, expire time.Duration, handle gin.HandlerFunc, opts ...Option) gin.HandlerFunc
Cache user must pass store and store expiration time to cache and with custom option. default caching response with uri, which use PageCachePrefix
func CacheWithRequestPath ¶
func CacheWithRequestPath(store persist.Store, expire time.Duration, handle gin.HandlerFunc, opts ...Option) gin.HandlerFunc
CacheWithRequestPath a shortcut function for caching response with url path, which discard the query params
func CacheWithRequestURI ¶
func CacheWithRequestURI(store persist.Store, expire time.Duration, handle gin.HandlerFunc, opts ...Option) gin.HandlerFunc
CacheWithRequestURI a shortcut function for caching response with uri
func GenerateKeyWithPrefix ¶
GenerateKeyWithPrefix generate key with GenerateKeyWithPrefix and u, if key is larger than 200,it will use sha1.Sum key like: prefix+u or prefix+sha1(u)
func GenerateRequestPathKey ¶
GenerateRequestPathKey generate key with PageCachePrefix and request Path
Types ¶
type BodyCache ¶
type BodyCache struct { Status int Header http.Header Data []byte // contains filtered or unexported fields }
BodyCache body cache store
func (*BodyCache) MarshalBinary ¶ added in v0.0.5
func (*BodyCache) UnmarshalBinary ¶ added in v0.0.5
type BodyWriter ¶
type BodyWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
BodyWriter dup response writer body
func (*BodyWriter) Write ¶
func (w *BodyWriter) Write(b []byte) (int, error)
Write writes the data to the connection as part of an HTTP reply.
func (*BodyWriter) WriteString ¶
func (w *BodyWriter) WriteString(s string) (int, error)
WriteString the string into the response body.
type Discard ¶
type Discard struct{}
Discard is an logger on which all Write calls succeed without doing anything.
func NewDiscard ¶
func NewDiscard() Discard
NewDiscard a discard logger on which always succeed without doing anything
type JSONEncoding ¶ added in v0.0.5
type JSONEncoding struct{}
type JSONGzipEncoding ¶ added in v0.0.5
type JSONGzipEncoding struct{}
type Option ¶
type Option func(c *Config)
Option custom option
func WithBodyCachePool ¶
WithBodyCachePool custom body cache pool, default is private cache pool.
func WithEncoding ¶ added in v0.0.5
WithEncoding custom Encoding, default is JSONEncoding.
func WithGenerateKey ¶
WithGenerateKey custom generate key ,default is GenerateRequestURIKey.
func WithRandDuration ¶
WithRandDuration custom rand duration for expire, default return zero expiration time always expire + rand()
func WithSingleflight ¶
func WithSingleflight(group *singleflight.Group) Option
WithSingleflight custom single flight group, default is private single flight group.