cache

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache

func Cache(opts ...Option) gin.HandlerFunc

Cache returns a cache handler

func CacheByPath

func CacheByPath() gincache.GetCacheStrategyByRequest

CacheByPath generates cache key by request path

func CacheByUri

func CacheByUri(ignoreOrder bool) gincache.GetCacheStrategyByRequest

CacheByUri generates cache key by request uri, if ignoreOrder is true, all query parameters will be sorted.

func NewMemStore

func NewMemStore(ttl time.Duration) *persist.MemoryStore

Types

type Option

type Option func(options *Options)

func WithCacheOption

func WithCacheOption(cacheOpts ...gincache.Option) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithStore

func WithStore(store persist.CacheStore) Option

func WithStrategy

func WithStrategy(strategy gincache.GetCacheStrategyByRequest) Option

func WithTTL

func WithTTL(ttl time.Duration) Option

type Options

type Options struct {
	CacheOpts []gincache.Option
	Prefix    string
	TTl       time.Duration
	Store     persist.CacheStore
	Strategy  gincache.GetCacheStrategyByRequest
}

type RedisStore

type RedisStore struct {
	RedisClient *redis.Client
}

RedisStore store http response in redis.(v9 adapter)

func NewRedisStore

func NewRedisStore(redisClient *redis.Client) *RedisStore

NewRedisStore create a redis memory store with redis client

func (*RedisStore) Delete

func (store *RedisStore) Delete(key string) error

Delete remove key in redis, do nothing if key doesn't exist

func (*RedisStore) Get

func (store *RedisStore) Get(key string, value interface{}) error

Get retrieves an item from redis, if key doesn't exist, return ErrCacheMiss

func (*RedisStore) Set

func (store *RedisStore) Set(key string, value interface{}, expire time.Duration) error

Set put key value pair to redis, and expire after expireDuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL