cache

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Barrier added in v0.23.0

type Barrier[K comparable] struct {
	// contains filtered or unexported fields
}

A Barrier is a mutual exclusion lock per key K.

The zero value for a Barrier is an unlocked mutex.

A Barrier must not be copied after first use.

func (*Barrier[K]) Lock added in v0.23.0

func (b *Barrier[K]) Lock(key K)

Lock locks the key.

If the key is already in use, the calling goroutine blocks until the key is available.

func (*Barrier[K]) Unlock added in v0.23.0

func (b *Barrier[K]) Unlock(key K)

Unlock unlocks the key. It is a run-time error if the key is not locked on entry to Unlock.

A Barrier is not associated with a particular goroutine. It is allowed for one goroutine to lock one Barrier key and then arrange for another goroutine to unlock this key.

type Cow added in v0.23.0

type Cow[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cow is a copy-on-write cache.

A Cow is optimized for many concurrent reads since any read operation does not require a lock.

However, a Cow is not well suited for frequent updates since it applies changes to a new copy.

The zero Cow is empty and ready for use. A Cow must not be copied after first use.

func NewCow added in v0.23.0

func NewCow[K comparable, V any](capacity int) *Cow[K, V]

NewCow returns a new copy-on-write cache with the given capacity that can hold at most N entries at the same time; N being the capacity.

func (*Cow[K, V]) Add added in v0.23.0

func (c *Cow[K, V]) Add(key K, value V) bool

Add adds the value if and only if no such entry already exists, and reports whether the value has been added.

As long as the Cow has reached its capacity limit, if set, Add does not add the value and returns false.

func (*Cow[K, V]) Clone added in v0.23.0

func (c *Cow[K, V]) Clone() *Cow[K, V]

Clone returns a copy of the Cow.

func (*Cow[K, V]) Delete added in v0.23.0

func (c *Cow[K, V]) Delete(key K) bool

Delete removes the given entry and reports whether it was present.

func (*Cow[K, V]) DeleteAll added in v0.23.0

func (c *Cow[K, V]) DeleteAll()

DeleteAll removes all entries.

func (*Cow[K, V]) DeleteFunc added in v0.23.0

func (c *Cow[K, V]) DeleteFunc(f func(K, V) bool)

DeleteFunc calls f for each entry and removes any entry for which f returns true

func (*Cow[K, V]) Get added in v0.23.0

func (c *Cow[K, V]) Get(key K) (v V, ok bool)

Get returns the value associated with the given key, if any, and reports whether a value has been found.

func (*Cow[K, _]) Keys added in v0.23.0

func (c *Cow[K, _]) Keys() []K

Keys returns a slice of all keys of the Cow. It never returns nil.

func (*Cow[K, V]) Set added in v0.23.0

func (c *Cow[K, V]) Set(key K, value V) bool

Set adds the key value pair, or replaces an existing value. It reports whether the given value has been stored.

If the Cow has reached its capacity limit, if set, Set does not add the value and returns false. However, it still replaces existing values, since this does not increase the size of the Cow.

Jump to

Keyboard shortcuts

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