Documentation
¶
Index ¶
- Constants
- Variables
- func AppendToSlice[T ScalarType](c *Cache, key string, val T) error
- func Decrease[T NumType](c *Cache, key string, val T) (T, error)
- func Delete(c *Cache, key string)
- func DeleteFromMap[T ScalarType](c *Cache, key string, name string) error
- func DeleteKeys(c *Cache, keys []string)
- func Exists(c *Cache, key string) bool
- func Get[T ValType](c *Cache, key string) (retV T, retErr error)
- func GetMapCopy[T ScalarType](c *Cache, key string) (retV map[string]T, retErr error)
- func GetSliceCopy[T ScalarType](c *Cache, key string) (retV []T, retErr error)
- func GetTTL(c *Cache, key string) (time.Duration, error)
- func GetWithTTL[T ValType](c *Cache, key string) (T, time.Duration, error)
- func Increase[T NumType](c *Cache, key string, val T) (T, error)
- func InsertToMap[T ScalarType](c *Cache, key string, name string, val T) error
- func Keys(c *Cache) []string
- func Len(c *Cache) int
- func LenValid(c *Cache) int
- func Set[T ValType](c *Cache, key string, val T, ttl time.Duration)
- type Cache
- type FilePersister
- type Item
- type MapType
- type NumType
- type Persister
- type ScalarType
- type SliceType
- type ValType
Constants ¶
Variables ¶
View Source
var ( ErrNotExists = errors.New("key not exists") ErrInvalidType = errors.New("invalid type") )
Functions ¶
func AppendToSlice ¶ added in v0.3.1
func AppendToSlice[T ScalarType](c *Cache, key string, val T) error
Append scalar to an existing slice cache
func DeleteFromMap ¶ added in v0.3.1
func DeleteFromMap[T ScalarType](c *Cache, key string, name string) error
Delete value from an existing map
func DeleteKeys ¶ added in v0.3.1
func Get ¶
WARNING: If value is in SliceType or MapType, the operation on the returned value is not thread-safe.
func GetMapCopy ¶ added in v0.3.1
func GetMapCopy[T ScalarType](c *Cache, key string) (retV map[string]T, retErr error)
Note: Thread-safe but expensive
func GetSliceCopy ¶ added in v0.3.1
func GetSliceCopy[T ScalarType](c *Cache, key string) (retV []T, retErr error)
Note: thread-safe but expensive
func GetWithTTL ¶ added in v0.3.1
func InsertToMap ¶ added in v0.3.1
func InsertToMap[T ScalarType](c *Cache, key string, name string, val T) error
Insert scalar to an existing map cache
Types ¶
type FilePersister ¶ added in v0.2.0
type FilePersister struct {
FilePath string
}
type Item ¶
type Item struct { Object interface{} ExpireMs int64 // expiration time in ms, never expire if equals to `kNoExpiration` }
type MapType ¶ added in v0.3.1
type MapType interface { map[string]string | map[string]bool | map[string]float32 | map[string]float64 | map[string]int | map[string]int8 | map[string]int16 | map[string]int32 | map[string]int64 | map[string]uint | map[string]uint8 | map[string]uint16 | map[string]uint32 | map[string]uint64 }
Map types are not recommended to use.
type ScalarType ¶
type SliceType ¶
type SliceType interface { []string | []bool | []float32 | []float64 | []int | []int8 | []int16 | []int32 | []int64 | []uint | []uint8 | []uint16 | []uint32 | []uint64 }
Slice types are not recommended to use.
type ValType ¶
type ValType interface { ScalarType | SliceType | MapType }
Click to show internal directories.
Click to hide internal directories.