Documentation
¶
Index ¶
Constants ¶
View Source
const DefaultInterval = time.Second
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Has returns whether the key exists.
Has(key string) (has bool)
// Set key-value, if the key exists, it will be overwritten.
Set(key string, val any, opts ...ItemOption)
// Get returns the value of the key, if the key does not exist, it returns false.
Get(key string) (val any, has bool)
// Del deletes the key.
Del(key string) (ok bool)
// GetDel returns the value of the key and deletes the key.
GetDel(key string) (val any, has bool)
// GetSet returns the value of the key and sets the new value.
GetSet(key string, newVal any, opts ...ItemOption) (oldVal any, has bool)
// SetX sets the key-value, if the key exists, it will not be overwritten.
SetX(key string, val any, opts ...ItemOption) (ok bool)
// DelExpired deletes the expired key.
DelExpired(key string) (has, exp bool)
// All returns all key-value.
All() (kvs map[string]any)
// Len returns the number of key-value.
Len() int
// Clear deletes all key-value.
Clear() int
// TTL returns the remaining time of the key.
TTL(key string) (ttl time.Duration, has bool)
// Expire sets the remaining time of the key.
Expire(key string, ttl time.Duration) (ok bool)
}
Cache interface
type ItemOption ¶
type ItemOption func(i *item)
ItemOption item option
func WithItemDur ¶
func WithItemDur(d time.Duration) ItemOption
WithItemDur set item expire duration
type Option ¶
type Option func(opts *options)
func WithExpireFun ¶
WithExpireFun set default expire callback
func WithInterval ¶
WithInterval set expire check interval
Click to show internal directories.
Click to hide internal directories.