Documentation ¶
Index ¶
- Constants
- Variables
- func Cache() echo.MiddlewareFunc
- func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc
- func CopyMap[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
- func DefaultCacheKey(prefix string, req *http.Request) string
- func DefaultCacheSkipper(c echo.Context) bool
- func DefaultCanCacheResponseSkipper(c echo.Context) bool
- type BoltAdapter
- type CacheAdapter
- type CacheConfig
- type CacheKeyFunc
- type Encoder
- type JSONEncoder
- type Marshaler
- type MemoryAdapter
- type MemoryType
- type Metrics
- type MsgpackEncoder
- type RedisAdapter
- type Response
- type SQLAdapter
- type SQLAdapterOption
- type Unmarshaler
Constants ¶
View Source
const ( SizeKB int64 = 1024 SizeMB int64 = 1024 * SizeKB )
View Source
const ( SQLite dbName = iota PostgreSQL MySQL )
Variables ¶
View Source
var ( DefaultCachePrefix = "cache" DefaultCacheDuration = time.Duration(0) DefaultCacheConfig = CacheConfig{ Skipper: DefaultCacheSkipper, CanCacheResponse: DefaultCanCacheResponseSkipper, CachePrefix: DefaultCachePrefix, CacheDuration: DefaultCacheDuration, CacheKey: DefaultCacheKey, } )
View Source
var DefaultSQLAdapterOption = SQLAdapterOption{ Ctx: context.Background(), TableName: "echo_cache", DBName: SQLite, }
Functions ¶
func CacheWithConfig ¶
func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc
func CopyMap ¶
func CopyMap[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
Copy from std lib "maps"
func DefaultCacheSkipper ¶
func DefaultCacheSkipper(c echo.Context) bool
Cache default skipper only cache GET/HEAD method and headers not contain `Range`
func DefaultCanCacheResponseSkipper ¶
func DefaultCanCacheResponseSkipper(c echo.Context) bool
Default canCacheResponse skipper will skip response cache if: - response status code not in (200, 301, 308) - response headers not contains `set-cookie`
Types ¶
type BoltAdapter ¶
type BoltAdapter struct {
// contains filtered or unexported fields
}
func NewBoltAdapter ¶
func NewBoltAdapter(ctx context.Context, path string) *BoltAdapter
type CacheAdapter ¶
type CacheAdapter interface { Get(key string) ([]byte, error) Set(key string, val []byte, ttl time.Duration) error }
func NewMemoryAdapter ¶
func NewMemoryAdapter(size int, memoryType MemoryType) CacheAdapter
func NewRedisAdapter ¶
func NewRedisAdapter(opt *redis.Options) CacheAdapter
func NewSQLAdapter ¶
func NewSQLAdapter(option SQLAdapterOption) CacheAdapter
type CacheConfig ¶
type CacheConfig struct { Skipper middleware.Skipper CanCacheResponse middleware.Skipper CachePrefix string CacheKey CacheKeyFunc CacheDuration time.Duration Adapter CacheAdapter Encoder Encoder Metrics Metrics }
type Encoder ¶
type Encoder interface { Marshaler Unmarshaler }
Interface that marshal/unmarshal `Response`
type JSONEncoder ¶
type JSONEncoder struct{}
type MemoryAdapter ¶
type MemoryAdapter struct {
// contains filtered or unexported fields
}
type MemoryType ¶
type MemoryType int
const ( TYPE_SIMPLE MemoryType = iota + 1 TYPE_LRU TYPE_LFU TYPE_ARC )
func (MemoryType) String ¶
func (m MemoryType) String() string
type Metrics ¶
type Metrics interface { // The total number of cache hits CacheHits() // The total number of cache misses CacheMisses() // The current size of the cache in bytes CacheSize(size float64) // The time it takes for the middleware to retrieve data from the cache CacheLatency(latency float64) // The total number of errors encountered while interacting with the cache CacheError() }
type MsgpackEncoder ¶
type MsgpackEncoder struct{}
type RedisAdapter ¶
type RedisAdapter struct {
// contains filtered or unexported fields
}
type Response ¶
type SQLAdapter ¶
type SQLAdapter struct { SQLAdapterOption // contains filtered or unexported fields }
type SQLAdapterOption ¶
type Unmarshaler ¶
Click to show internal directories.
Click to hide internal directories.