Documentation
¶
Index ¶
- func CloseCache()
- type Cache
- type DiskCache
- func (d *DiskCache) Add(key any, value any, lifeSpan time.Duration)
- func (d *DiskCache) Clear() bool
- func (d *DiskCache) Close()
- func (d *DiskCache) Delete(key any)
- func (d *DiskCache) Get(key any) (any, bool)
- func (d *DiskCache) IsExist(key any) bool
- func (d *DiskCache) Range(f func(key, value any) bool)
- func (d *DiskCache) Set(key any, value any, duration time.Duration)
- func (d *DiskCache) Value(key any) (any, bool)
- type ICache
- type MemCache
- func (c *MemCache) Add(key any, value any, lifeSpan time.Duration)
- func (c *MemCache) AddWithError(key any, value any, lifeSpan time.Duration) error
- func (c *MemCache) Clear() bool
- func (cache *MemCache) Close()
- func (cache *MemCache) Delete(key any)
- func (cache *MemCache) Get(key any) (any, bool)
- func (c *MemCache) IsExist(key any) bool
- func (cache *MemCache) Range(f func(key, value any) bool)
- func (cache *MemCache) Set(key any, value any, duration time.Duration)
- func (cache *MemCache) SetWithError(key any, value any, duration time.Duration) error
- func (c *MemCache) Value(key any) (any, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseCache ¶
func CloseCache()
Types ¶
type ICache ¶
type ICache interface {
Add(key any, value any, lifeSpan time.Duration)
Value(key any) (any, bool)
IsExist(key any) bool
Clear() bool
Get(key any) (any, bool)
Set(key any, value any, duration time.Duration)
Range(f func(key, value any) bool)
Delete(key any)
Close()
}
func OnDiskCache ¶
func OnGetCache ¶
初始化一个cache cachename 缓存名字
func OnMemCache ¶
type MemCache ¶
type MemCache struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new cache that asynchronously cleans expired entries after the given time passes.
func (*MemCache) AddWithError ¶ added in v2.0.18
AddWithError clones and stores a value, returning invalid-key errors to the caller.
func (*MemCache) Close ¶
func (cache *MemCache) Close()
Close closes the cache and frees up resources.
func (*MemCache) Range ¶
Range calls f sequentially for each key and value present in the cache. If f returns false, range stops the iteration.
func (*MemCache) Set ¶
Set sets a value for the given key with an expiration duration. If the duration is 0 or less, it will be stored forever.
func (*MemCache) SetWithError ¶ added in v2.0.18
SetWithError stores a value and rejects keys that sync.Map cannot accept.