cache

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

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]) Len

func (a *Cache[K, V]) Len() int

Len returns the cache length.

func (*Cache[K, V]) Load added in v0.1.1

func (a *Cache[K, V]) Load(key K) (value V, ok bool)

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

func (a *Cache[K, V]) LoadAndDelete(key K) (value V, loaded bool)

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

func (a *Cache[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

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.

func (*Cache[K, V]) Range added in v0.1.1

func (a *Cache[K, V]) Range(f func(key K, value V) bool)

Range calls f sequentially for each key and value present in the cache. If f returns false, range stops the iteration.

func (*Cache[K, V]) Store added in v0.1.1

func (a *Cache[K, V]) Store(key K, value V)

Store sets the value for a key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL