Documentation
¶
Index ¶
- func AddPrefix(key string) string
- func Client() any
- func Close() error
- func DecrFloat(ctx context.Context, key string, value float64) (float64, error)
- func DecrInt(ctx context.Context, key string, value int64) (int64, error)
- func Delete(ctx context.Context, keys ...string) (int64, error)
- func Has(ctx context.Context, key string) (bool, error)
- func IncrFloat(ctx context.Context, key string, value float64) (float64, error)
- func IncrInt(ctx context.Context, key string, value int64) (int64, error)
- func Set(ctx context.Context, key string, value any, expiration ...time.Duration) error
- func SetCache(cache Cache)
- type Cache
- type Result
- type SetValueFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecrFloat ¶
DecrFloat decrements the float stored at key in the global cache by value and returns the resulting value.
func DecrInt ¶
DecrInt decrements the integer stored at key in the global cache by value and returns the resulting value.
func Delete ¶
Delete removes the given keys from the global cache and reports how many keys were actually deleted.
func IncrFloat ¶
IncrFloat increments the float stored at key in the global cache by value and returns the resulting value.
func IncrInt ¶
IncrInt increments the integer stored at key in the global cache by value and returns the resulting value.
func Set ¶
Set stores value under key in the global cache. The optional expiration controls the entry's time to live: when it is omitted a random duration within the configured expiration range is used, a value greater than 0 sets an explicit expiration, -1 keeps the existing expiration and a value less than -1 makes the entry never expire.
Types ¶
type Cache ¶
type Cache interface {
// Has reports whether the entry identified by key exists.
Has(ctx context.Context, key string) (bool, error)
// Get returns the value of key. The optional def is returned when the entry does not exist.
Get(ctx context.Context, key string, def ...any) Result
// Set stores value under key. The optional expiration controls the entry's time to live: when
// it is omitted a random duration within the configured expiration range is used, a value
// greater than 0 sets an explicit expiration, -1 keeps the existing expiration and a value
// less than -1 makes the entry never expire.
Set(ctx context.Context, key string, value any, expiration ...time.Duration) error
// GetSet returns the value of key, generating it with fn and storing it when the entry does not
// exist.
GetSet(ctx context.Context, key string, fn SetValueFunc) Result
// Delete removes the given keys and reports how many keys were actually deleted.
Delete(ctx context.Context, keys ...string) (int64, error)
// IncrInt increments the integer stored at key by value and returns the resulting value.
IncrInt(ctx context.Context, key string, value int64) (int64, error)
// IncrFloat increments the float stored at key by value and returns the resulting value.
IncrFloat(ctx context.Context, key string, value float64) (float64, error)
// DecrInt decrements the integer stored at key by value and returns the resulting value.
DecrInt(ctx context.Context, key string, value int64) (int64, error)
// DecrFloat decrements the float stored at key by value and returns the resulting value.
DecrFloat(ctx context.Context, key string, value float64) (float64, error)
// AddPrefix returns key prefixed with the cache's key prefix.
AddPrefix(key string) string
// Client returns the underlying cache client.
Client() any
// Close closes the cache.
Close() error
}
Cache is the interface implemented by cache backends.
type Result ¶
type Result interface {
// Err returns the error of the result, if any.
Err() error
// Result returns the raw value together with the error, if any.
Result() (value.Value, error)
// Int returns the cached value as an int.
Int() (int, error)
// Int8 returns the cached value as an int8.
Int8() (int8, error)
// Int16 returns the cached value as an int16.
Int16() (int16, error)
// Int32 returns the cached value as an int32.
Int32() (int32, error)
// Int64 returns the cached value as an int64.
Int64() (int64, error)
// Uint returns the cached value as a uint.
Uint() (uint, error)
// Uint8 returns the cached value as a uint8.
Uint8() (uint8, error)
// Uint16 returns the cached value as a uint16.
Uint16() (uint16, error)
// Uint32 returns the cached value as a uint32.
Uint32() (uint32, error)
// Uint64 returns the cached value as a uint64.
Uint64() (uint64, error)
// Float32 returns the cached value as a float32.
Float32() (float32, error)
// Float64 returns the cached value as a float64.
Float64() (float64, error)
// Bool returns the cached value as a bool.
Bool() (bool, error)
// String returns the cached value as a string.
String() (string, error)
// Duration returns the cached value as a time.Duration.
Duration() (time.Duration, error)
// Ints returns the cached value as a []int.
Ints() ([]int, error)
// Int8s returns the cached value as a []int8.
Int8s() ([]int8, error)
// Int16s returns the cached value as a []int16.
Int16s() ([]int16, error)
// Int32s returns the cached value as a []int32.
Int32s() ([]int32, error)
// Int64s returns the cached value as a []int64.
Int64s() ([]int64, error)
// Uints returns the cached value as a []uint.
Uints() ([]uint, error)
// Uint8s returns the cached value as a []uint8.
Uint8s() ([]uint8, error)
// Uint16s returns the cached value as a []uint16.
Uint16s() ([]uint16, error)
// Uint32s returns the cached value as a []uint32.
Uint32s() ([]uint32, error)
// Uint64s returns the cached value as a []uint64.
Uint64s() ([]uint64, error)
// Float32s returns the cached value as a []float32.
Float32s() ([]float32, error)
// Float64s returns the cached value as a []float64.
Float64s() ([]float64, error)
// Bools returns the cached value as a []bool.
Bools() ([]bool, error)
// Strings returns the cached value as a []string.
Strings() ([]string, error)
// Bytes returns the cached value as a []byte.
Bytes() ([]byte, error)
// Durations returns the cached value as a []time.Duration.
Durations() ([]time.Duration, error)
// Slice returns the cached value as a []any.
Slice() ([]any, error)
// Map returns the cached value as a map[string]any.
Map() (map[string]any, error)
// Scan scans the cached value into the object pointed to by pointer.
Scan(pointer any) error
}
Result is the interface that represents a cache read result. It provides methods to convert the cached value into the supported types.
func Get ¶
Get returns the value of key from the global cache. The optional def is returned when the entry does not exist.
type SetValueFunc ¶
SetValueFunc is the callback used to generate a cache value. It returns the generated value and an error.