store

package
v0.0.0-...-1746241 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 1 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

Store defines a concurrent safe in memory key-value data store.

func New

func New[T any](data map[string]T) *Store[T]

New creates a new Store[T] instance with a shallow copy of the provided data (if any).

func (*Store[T]) Get

func (s *Store[T]) Get(key string) T

Get returns a single element value from the store.

If key is not set, the zero T value is returned.

func (*Store[T]) GetAll

func (s *Store[T]) GetAll() map[string]T

GetAll returns a shallow copy of the current store data.

func (*Store[T]) Has

func (s *Store[T]) Has(key string) bool

Has checks if element with the specified key exist or not.

func (*Store[T]) Length

func (s *Store[T]) Length() int

Length returns the current number of elements in the store.

func (*Store[T]) Remove

func (s *Store[T]) Remove(key string)

Remove removes a single entry from the store.

Remove does nothing if key doesn't exist in the store.

func (*Store[T]) RemoveAll

func (s *Store[T]) RemoveAll()

RemoveAll removes all the existing store entries.

func (*Store[T]) Reset

func (s *Store[T]) Reset(newData map[string]T)

Reset clears the store and replaces the store data with a shallow copy of the provided newData.

func (*Store[T]) Set

func (s *Store[T]) Set(key string, value T)

Set sets (or overwrite if already exist) a new value for key.

func (*Store[T]) SetIfLessThanLimit

func (s *Store[T]) SetIfLessThanLimit(key string, value T, maxAllowedElements int) bool

SetIfLessThanLimit sets (or overwrite if already exist) a new value for key.

This method is similar to Set() but **it will skip adding new elements** to the store if the store length has reached the specified limit. false is returned if maxAllowedElements limit is reached.

Jump to

Keyboard shortcuts

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