Documentation
¶
Index ¶
- type Cache
- func (a *Cache[K, V]) Delete(key K)
- func (a *Cache[K, V]) Len() int
- func (a *Cache[K, V]) Load(key K) (value V, ok bool)
- func (a *Cache[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (a *Cache[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (a *Cache[K, V]) Range(f func(key K, value V) bool)
- func (a *Cache[K, V]) Store(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache represents a cache manager.
func New ¶
func New[K comparable, V any](ttl time.Duration) *Cache[K, V]
New creates a new cache manager.
func (*Cache[K, V]) Delete ¶
func (a *Cache[K, V]) Delete(key K)
Delete deletes the value for a key.
func (*Cache[K, V]) Load ¶ added in v0.1.1
Load returns the value stored in the cache for a key, or zero value if no value is present. The ok result indicates whether value was found in the cache.
func (*Cache[K, V]) LoadAndDelete ¶ added in v0.1.1
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*Cache[K, V]) LoadOrStore ¶ added in v0.1.1
LoadOrStore returns the value by key, if not exist, puts value in the key, and returns it. The loaded result is true if the value was loaded, false if stored.
Click to show internal directories.
Click to hide internal directories.