cache

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finite

type Finite[T any] struct {
	C <-chan T // Objects can be pulled from the cache via this channel. This channel will be closed when the cache is closed. Note that a cache is unordered: the order in which objects are recovered from the cache via this channel has no relation to the order in which they were added to the cache.
	// contains filtered or unexported fields
}

Finite is a cache of fixed size used for storing unordered data. It will flush automatically when full, and on close.

func NewFinite

func NewFinite[T any](maxSize int, flush FlushFunc[T]) *Finite[T]

NewFinite returns a new finite cache of maximum size maxSize using the given flush function.

func (*Finite[T]) Add

func (c *Finite[T]) Add(x T) error

Add places x onto the cache.

func (*Finite[_]) Close

func (c *Finite[_]) Close() error

Close closes the cache. Any cached data will be flushed.

func (*Finite[_]) Err

func (c *Finite[_]) Err() (err error)

Err returns the any error.

func (*Finite[_]) Flush

func (c *Finite[_]) Flush()

Flush flushes the cache.

func (*Finite[_]) FlushAllButN

func (c *Finite[_]) FlushAllButN(N int)

FlushAllButN flushes all but N elements from the cache.

func (*Finite[_]) Len

func (c *Finite[_]) Len() (n int)

Len returns the number of objects currently in the cache.

func (*Finite[_]) SetError

func (c *Finite[_]) SetError(err error)

SetError places the cache in an error state.

type FlushFunc

type FlushFunc[T any] func([]T) error

FlushFunc defines a function to be used to flush the cache.

Jump to

Keyboard shortcuts

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