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: - interface{}: The value associated with the key. - bool: A boolean indicating whether the key exists in the storage.
func Store ¶
func Store(key string, value interface{})
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: interface{} 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]interface{} for storing the data with string keys.
func New ¶
func New() *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.
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: - interface{}: 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: interface{} The value to store, which can be of any type.