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 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 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 Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config config for cache
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 Logger ¶
type Logger interface {
Errorf(format string, args ...interface{})
}
Logger logger interface
type Option ¶
type Option func(c *Config)
Option custom option
func WithBodyCachePool ¶
WithBodyCachePool custom body cache pool, default is private cache pool.
func WithGenerateKey ¶
WithGenerateKey custom generate key ,default is GenerateRequestURIKey.
func WithSingleflight ¶
func WithSingleflight(group *singleflight.Group) Option
WithSingleflight custom single flight group, default is private single flight group.

