Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterGoCacheDriver(driverName string, memCache *gocache.Cache, cacheKeyPrefix string) error
- func RegisterRedisDriver(driverName string, redis *redis.Client, cacheKeyPrefix string) error
- func SetDefault(driverName string)
- func UnSetDefault()
- 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]) Del(key string) 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), force bool) (result V, err error)
- func (d *GoCacheDriver[V]) RememberForever(key string, callback func() (V, error), force bool) (V, error)
- func (d *GoCacheDriver[V]) RememberMany(keys []string, ttl time.Duration, ...) (map[string]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]
- func (d *GoCacheDriver[V]) WithSerializer(serializer Serializer) 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]) Del(key string) 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), force bool) (result V, err error)
- func (d *RedisDriver[V]) RememberForever(key string, callback func() (V, error), force bool) (V, error)
- func (d *RedisDriver[V]) RememberMany(keys []string, ttl time.Duration, ...) (map[string]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]
- func (d *RedisDriver[V]) WithSerializer(serializer Serializer) 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 ¶
func RegisterGoCacheDriver ¶ added in v0.3.0
RegisterGoCacheDriver registers a GoCache driver with the given driverName. This function creates a new driver based on the provided go-cache client and registers it in registerDrivers.
func RegisterRedisDriver ¶ added in v0.3.0
RegisterRedisDriver registers a Redis driver with the given driverName. This function creates a new driver based on the provided redis client and registers it in registerDrivers.
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 // Del Remove an item from the cache alia Forget. Del(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), force bool) (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), force bool) (V, error) // RememberMany Get many item from the cache, or execute the given Closure and store the result. RememberMany(keys []string, ttl time.Duration, callback func(notHitKeys []string) (map[string]V, error), force bool) (map[string]V, error) // TTL Get cache ttl TTL(key string) (time.Duration, error) // WithCtx with context WithCtx(ctx context.Context) Driver[V] // WithSerializer with cache serializer WithSerializer(serializer Serializer) Driver[V] }
Driver cache driver interface
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]) Del ¶ added in v0.5.1
func (d *GoCacheDriver[V]) Del(key string) 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), force bool) (V, error)
func (*GoCacheDriver[V]) RememberMany ¶ added in v0.4.0
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
func (*GoCacheDriver[V]) TTL ¶ added in v0.1.0
func (d *GoCacheDriver[V]) TTL(key string) (ttl time.Duration, err error)
func (*GoCacheDriver[V]) WithCtx ¶ added in v0.1.0
func (d *GoCacheDriver[V]) WithCtx(ctx context.Context) Driver[V]
func (*GoCacheDriver[V]) WithSerializer ¶ added in v0.3.0
func (d *GoCacheDriver[V]) WithSerializer(serializer Serializer) Driver[V]
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
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]) Del ¶ added in v0.5.1
func (d *RedisDriver[V]) Del(key string) 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), force bool) (V, error)
func (*RedisDriver[V]) RememberMany ¶ added in v0.4.0
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
func (*RedisDriver[V]) TTL ¶ added in v0.1.0
func (d *RedisDriver[V]) TTL(key string) (ttl time.Duration, err error)
func (*RedisDriver[V]) WithCtx ¶ added in v0.1.0
func (d *RedisDriver[V]) WithCtx(ctx context.Context) Driver[V]
func (*RedisDriver[V]) WithSerializer ¶ added in v0.3.0
func (d *RedisDriver[V]) WithSerializer(serializer Serializer) Driver[V]
Click to show internal directories.
Click to hide internal directories.