Documentation
¶
Index ¶
- Constants
- type Cache
- type Lock
- type Memory
- func (r *Memory) Add(key string, value any, t time.Duration) bool
- func (r *Memory) Decrement(key string, value ...int64) (int64, error)
- func (r *Memory) Flush() bool
- func (r *Memory) Forever(key string, value any) bool
- func (r *Memory) Forget(key string) bool
- func (r *Memory) Get(key string, def ...any) any
- func (r *Memory) GetBool(key string, def ...bool) bool
- func (r *Memory) GetInt(key string, def ...int) int
- func (r *Memory) GetInt64(key string, def ...int64) int64
- func (r *Memory) GetString(key string, def ...string) string
- func (r *Memory) Has(key string) bool
- func (r *Memory) Increment(key string, value ...int64) (int64, error)
- func (r *Memory) Lock(key string, t ...time.Duration) *Lock
- func (r *Memory) Pull(key string, def ...any) any
- func (r *Memory) Put(key string, value any, t time.Duration) error
- func (r *Memory) Remember(key string, seconds time.Duration, callback func() (any, error)) (any, error)
- func (r *Memory) RememberForever(key string, callback func() (any, error)) (any, error)
- func (r *Memory) WithContext(ctx context.Context) Cache
Constants ¶
View Source
const NoExpiration time.Duration = 0
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Add an item in the cache if the key does not exist.
Add(key string, value any, t time.Duration) bool
// Decrement decrements the value of an item in the cache.
Decrement(key string, value ...int64) (int64, error)
// Forever add an item in the cache indefinitely.
Forever(key string, value any) bool
// Forget removes an item from the cache.
Forget(key string) bool
// Flush remove all items from the cache.
Flush() bool
// Get retrieve an item from the cache by key.
Get(key string, def ...any) any
// GetBool retrieves an item from the cache by key as a boolean.
GetBool(key string, def ...bool) bool
// GetInt retrieves an item from the cache by key as an integer.
GetInt(key string, def ...int) int
// GetInt64 retrieves an item from the cache by key as a 64-bit integer.
GetInt64(key string, def ...int64) int64
// GetString retrieves an item from the cache by key as a string.
GetString(key string, def ...string) string
// Has check an item exists in the cache.
Has(key string) bool
// Increment increments the value of an item in the cache.
Increment(key string, value ...int64) (int64, error)
// Lock get a lock instance.
Lock(key string, t ...time.Duration) *Lock
// Put Driver an item in the cache for a given time.
Put(key string, value any, t time.Duration) error
// Pull retrieve an item from the cache and delete it.
Pull(key string, def ...any) any
// Remember gets an item from the cache, or execute the given Closure and store the result.
Remember(key string, ttl time.Duration, callback func() (any, error)) (any, error)
// RememberForever get an item from the cache, or execute the given Closure and store the result forever.
RememberForever(key string, callback func() (any, error)) (any, error)
// WithContext returns a new Cache instance with the given context.
WithContext(ctx context.Context) Cache
}
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func (*Lock) ForceRelease ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) Remember ¶
func (r *Memory) Remember(key string, seconds time.Duration, callback func() (any, error)) (any, error)
Remember Get an item from the cache, or execute the given Closure and store the result.
func (*Memory) RememberForever ¶
RememberForever Get an item from the cache, or execute the given Closure and store the result forever.
Click to show internal directories.
Click to hide internal directories.