memory

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear clears the memory storage. It invokes the Clear method on the singleton Memory instance, resetting the storage to its initial state.

func Delete

func Delete(key string)

Delete removes a value from the memory storage based on the given key. It deletes the value associated with the key from the singleton Memory instance.

Parameters: - key: string The key corresponding to the value to be removed.

func Exists

func Exists(key string) bool

Exists checks if a key exists in the memory storage. It checks the presence of a key in the singleton Memory instance.

Parameters: - key: string The key to check in the storage.

Returns: - bool: True if the key exists in the storage, false otherwise.

func Read

func Read(key string) (any, bool)

Read retrieves a value from the memory storage based on the given key. It returns the value associated with the key and a boolean indicating whether the key exists in the storage.

Parameters: - key: string The key corresponding to the value to retrieve.

Returns: - any: The value associated with the key. - bool: A boolean indicating whether the key exists in the storage.

func Store

func Store(key string, value any)

Store stores a value in the memory storage. It saves the value in the singleton Memory instance, accessible via the provided key.

Parameters: - key: string The key to store the value under. - value: any The value to store, can be of any type.

Types

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory represents an in-memory storage implementation. This structure provides thread-safe operations for storing and retrieving data in memory.

Attributes: - mu: sync.RWMutex for synchronizing read-write access to the data. - data: map[string]any for storing the data with string keys.

func NewMemory added in v0.23.20

func NewMemory() *Memory

New creates a new instance of the Memory storage. It initializes the storage with an empty map.

Returns: - *Memory: A pointer to a newly created Memory instance with initialized storage.

func (*Memory) Clear

func (m *Memory) Clear()

Clear removes all data from the memory storage. It locks the storage for write operations, clears the data, and then unlocks it.

func (*Memory) Delete

func (m *Memory) Delete(key string) bool

Delete removes the value associated with the specified key from the memory storage. It locks the storage for write operations, removes the value, and then unlocks it.

Parameters: - key: string The key for which to remove the associated value. Returns: - bool: A boolean indicating whether the key remove from the storage.

func (*Memory) Exists

func (m *Memory) Exists(key string) bool

Exists checks if the specified key exists in the memory storage. It locks the storage for read operations, checks for key existence, and then unlocks it.

Parameters: - key: string The key to check for existence.

Returns: - bool: A boolean indicating whether the key exists in the storage.

func (*Memory) Read

func (m *Memory) Read(key string) (any, bool)

Read retrieves the value associated with the specified key from the memory storage. It locks the storage for read operations, retrieves the value, and then unlocks it.

Parameters: - key: string The key for which to retrieve the associated value.

Returns: - any: The value associated with the key. - bool: A boolean indicating whether the key exists in the storage.

func (*Memory) Store

func (m *Memory) Store(key string, value any) bool

Store adds or updates a value in the memory storage with the specified key. It locks the storage for write operations, stores/updates the value, and then unlocks it.

Parameters: - key: string The key to associate with the value. - value: any The value to store, which can be of any type. Returns: - bool: A boolean indicating whether the key is stored in the storage.

type Shared added in v0.23.20

type Shared struct {
	// contains filtered or unexported fields
}

Shared represents a shared memory storage.

func NewSharedMemory added in v0.23.20

func NewSharedMemory() *Shared

NewSharedMemory creates a new instance of Shared. It initializes the shards with empty memory.

Returns: - s: *Shared - The new instance of Shared.

func (*Shared) Delete added in v0.23.20

func (s *Shared) Delete(key string)

Delete removes a value from the shared memory storage.

Parameters: - key: string - The key used to delete the value. Delete deletes the value associated with the given key from the shared memory storage.

func (*Shared) Exists added in v0.23.20

func (s *Shared) Exists(key string) bool

Exists checks if a key exists in the shared memory storage. It returns true if the key exists, otherwise it returns false.

Parameters: - key: string - The key to check for existence in the shared memory storage.

Returns: - exists: bool - True if the key exists, false otherwise.

func (*Shared) Read added in v0.23.20

func (s *Shared) Read(key string) (interface{}, bool)

Read retrieves a value from the shared memory storage.

Parameters: - key: string - The key used to retrieve the value.

Returns: - value: interface{} - The retrieved value. - exists: bool - True if the value exists, false otherwise.

func (*Shared) Store added in v0.23.20

func (s *Shared) Store(key string, value interface{}) bool

Store stores a value in the shared memory storage.

Parameters: - key: string - The key used to store the value. - value: interface{} - The value to be stored.

Returns: - success: bool - True if the value was successfully stored, false otherwise.

Jump to

Keyboard shortcuts

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