Documentation
¶
Index ¶
- Constants
- Variables
- type Driver
- type DriverType
- type GoCacheDriver
- func (d *GoCacheDriver[V]) Add(key string, value V, t time.Duration) error
- func (d *GoCacheDriver[V]) Decrement(key string, n V) (ret V, err error)
- func (d *GoCacheDriver[V]) Flush() error
- func (d *GoCacheDriver[V]) Forever(key string, value V) error
- func (d *GoCacheDriver[V]) Forget(key string) error
- func (d *GoCacheDriver[V]) Get(key string) (result V, err error)
- func (d *GoCacheDriver[V]) Has(key string) (bool, error)
- func (d *GoCacheDriver[V]) Increment(key string, n V) (ret V, err error)
- func (d *GoCacheDriver[V]) Many(keys []string) (map[string]V, error)
- func (d *GoCacheDriver[V]) Remember(key string, ttl time.Duration, callback func() (V, error)) (result V, err error)
- func (d *GoCacheDriver[V]) RememberForever(key string, callback func() (V, error)) (V, error)
- func (d *GoCacheDriver[V]) Set(key string, value V, t time.Duration) error
- func (d *GoCacheDriver[V]) SetMany(many []Many[V]) error
- func (d *GoCacheDriver[V]) SetNumber(key string, value V, t time.Duration) error
- func (d *GoCacheDriver[V]) TTL(key string) (ttl time.Duration, err error)
- func (d *GoCacheDriver[V]) WithCtx(ctx context.Context) Driver[V]
- type JSONSerializer
- type Many
- type OptionFunc
- type RedisDriver
- func (d *RedisDriver[V]) Add(key string, value V, t time.Duration) error
- func (d *RedisDriver[V]) Decrement(key string, n V) (ret V, err error)
- func (d *RedisDriver[V]) Flush() error
- func (d *RedisDriver[V]) Forever(key string, value V) error
- func (d *RedisDriver[V]) Forget(key string) error
- func (d *RedisDriver[V]) Get(key string) (V, error)
- func (d *RedisDriver[V]) Has(key string) (bool, error)
- func (d *RedisDriver[V]) Increment(key string, n V) (ret V, err error)
- func (d *RedisDriver[V]) Many(keys []string) (map[string]V, error)
- func (d *RedisDriver[V]) Remember(key string, ttl time.Duration, callback func() (V, error)) (result V, err error)
- func (d *RedisDriver[V]) RememberForever(key string, callback func() (V, error)) (V, error)
- func (d *RedisDriver[V]) Set(key string, value V, t time.Duration) error
- func (d *RedisDriver[V]) SetMany(many []Many[V]) error
- func (d *RedisDriver[V]) SetNumber(key string, value V, t time.Duration) error
- func (d *RedisDriver[V]) TTL(key string) (ttl time.Duration, err error)
- func (d *RedisDriver[V]) WithCtx(ctx context.Context) Driver[V]
- type Serializer
Constants ¶
View Source
const ( // NoExpirationTTL no expiration ttl NoExpirationTTL = time.Duration(-1) // ItemNotExistedTTL item not existed ttl ItemNotExistedTTL = time.Duration(-2) )
Variables ¶
View Source
var ( ErrCacheMiss = errors.New("cache not exists") ErrCacheExisted = errors.New("cache already existed") )
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver[V any] interface { // Add Store an item in the cache if the key doesn't exist. Add(key string, value V, t time.Duration) error // Set Store an item in the cache for a given number of seconds. Set(key string, value V, t time.Duration) error // SetMany Store multiple items in the cache for a given number of seconds. SetMany(many []Many[V]) error // Forever Store an item in the cache indefinitely. Forever(key string, value V) error // Forget Remove an item from the cache. Forget(key string) error // Flush Remove all items from the cache. Flush() error // Get Retrieve an item from the cache by key. Get(key string) (V, error) // Has Determined if an item exists in the cache. Has(key string) (bool, error) // Many Retrieve multiple items from the cache by key. // Items not found in the cache will have a nil value. Many(keys []string) (map[string]V, error) // SetNumber set the int64 value of an item in the cache. SetNumber(key string, value V, t time.Duration) error // Increment the value of an item in the cache. Increment(key string, n V) (V, error) // Decrement the value of an item in the cache. Decrement(key string, n V) (V, error) // Remember Get an item from the cache, or execute the given Closure and store the result. Remember(key string, ttl time.Duration, callback func() (V, error)) (V, error) // RememberForever Get an item from the cache, or execute the given Closure and store the result forever. RememberForever(key string, callback func() (V, error)) (V, error) // TTL Get cache ttl TTL(key string) (time.Duration, error) // WithCtx with context WithCtx(ctx context.Context) Driver[V] }
Driver cache driver interface
func New ¶
func New[V any](driver DriverType, optionFns ...OptionFunc) (Driver[V], error)
type DriverType ¶
type DriverType string
DriverType DriverType
const ( // DriverRedis type redis DriverRedis DriverType = "redis" // DriverMemory type memory DriverMemory DriverType = "memory" )
type GoCacheDriver ¶
type GoCacheDriver[V any] struct { // contains filtered or unexported fields }
GoCacheDriver go-cache driver implemented
func (*GoCacheDriver[V]) Add ¶
func (d *GoCacheDriver[V]) Add(key string, value V, t time.Duration) error
func (*GoCacheDriver[V]) Decrement ¶ added in v0.1.0
func (d *GoCacheDriver[V]) Decrement(key string, n V) (ret V, err error)
func (*GoCacheDriver[V]) Flush ¶
func (d *GoCacheDriver[V]) Flush() error
func (*GoCacheDriver[V]) Forever ¶
func (d *GoCacheDriver[V]) Forever(key string, value V) error
func (*GoCacheDriver[V]) Forget ¶
func (d *GoCacheDriver[V]) Forget(key string) error
func (*GoCacheDriver[V]) Get ¶
func (d *GoCacheDriver[V]) Get(key string) (result V, err error)
func (*GoCacheDriver[V]) Increment ¶ added in v0.1.0
func (d *GoCacheDriver[V]) Increment(key string, n V) (ret V, err error)
func (*GoCacheDriver[V]) Many ¶
func (d *GoCacheDriver[V]) Many(keys []string) (map[string]V, error)
func (*GoCacheDriver[V]) RememberForever ¶
func (d *GoCacheDriver[V]) RememberForever(key string, callback func() (V, error)) (V, error)
func (*GoCacheDriver[V]) Set ¶ added in v0.1.0
func (d *GoCacheDriver[V]) Set(key string, value V, t time.Duration) error
func (*GoCacheDriver[V]) SetMany ¶ added in v0.1.0
func (d *GoCacheDriver[V]) SetMany(many []Many[V]) error
func (*GoCacheDriver[V]) SetNumber ¶ added in v0.1.0
func (d *GoCacheDriver[V]) SetNumber(key string, value V, t time.Duration) error
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer json serializer
func (*JSONSerializer) Serialize ¶
func (d *JSONSerializer) Serialize(v any) ([]byte, error)
Serialize Serialize data
func (*JSONSerializer) UnSerialize ¶
func (d *JSONSerializer) UnSerialize(data []byte, v any) error
UnSerialize UnSerialize data
type OptionFunc ¶
type OptionFunc func(driver *baseDriver) error
func WithMemCache ¶
func WithMemCache(memCache *gocache.Cache) OptionFunc
WithMemCache with a go-cache client
func WithRedisClient ¶
func WithRedisClient(redis *redis.Client) OptionFunc
WithRedisClient set a redis client
func WithSerializer ¶
func WithSerializer(serializer Serializer) OptionFunc
WithSerializer set a cache serializer
type RedisDriver ¶
type RedisDriver[V any] struct { // contains filtered or unexported fields }
RedisDriver go-redis driver implemented
func (*RedisDriver[V]) Add ¶
func (d *RedisDriver[V]) Add(key string, value V, t time.Duration) error
func (*RedisDriver[V]) Decrement ¶ added in v0.1.0
func (d *RedisDriver[V]) Decrement(key string, n V) (ret V, err error)
func (*RedisDriver[V]) Flush ¶
func (d *RedisDriver[V]) Flush() error
func (*RedisDriver[V]) Forever ¶
func (d *RedisDriver[V]) Forever(key string, value V) error
func (*RedisDriver[V]) Forget ¶
func (d *RedisDriver[V]) Forget(key string) error
func (*RedisDriver[V]) Get ¶
func (d *RedisDriver[V]) Get(key string) (V, error)
func (*RedisDriver[V]) Increment ¶ added in v0.1.0
func (d *RedisDriver[V]) Increment(key string, n V) (ret V, err error)
func (*RedisDriver[V]) RememberForever ¶
func (d *RedisDriver[V]) RememberForever(key string, callback func() (V, error)) (V, error)
func (*RedisDriver[V]) Set ¶ added in v0.1.0
func (d *RedisDriver[V]) Set(key string, value V, t time.Duration) error
func (*RedisDriver[V]) SetMany ¶ added in v0.1.0
func (d *RedisDriver[V]) SetMany(many []Many[V]) error
func (*RedisDriver[V]) SetNumber ¶ added in v0.1.0
func (d *RedisDriver[V]) SetNumber(key string, value V, t time.Duration) error
Click to show internal directories.
Click to hide internal directories.