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 ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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
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
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
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.