Skip to main content

StorageHardware UCMVirtual UCM

The storage library implements an interface to persistent memory.

storage.write

Flash Cycles Limit

Flash memory has a limited number of writes which can be performed before the flash reaches the end of life. On Enapter hardware UCMs it's about 60,000,000 writes of the 128 byte values (or 128 char strings).

If you want to store some data periodically and want your flash to work for at least 10 years, then the minimum interval for storage.write call is once per 5 seconds.

-- @param key string
-- @param value|nil string
-- @return string|nil
function storage.write(key, value) end

Writes the value to the persistent storage by key. Later the value can be accessed using storage.read by the same key. Writing nil is the same as calling storage.remove for the given key.

The key has length limit with 15 characters.

On success, the function returns nil. On failure, it returns an error message string.

Example

local err = storage.write("mykey", "myvalue")
if err ~= nil then
enapter.log("Cannot write value: " .. err, "error")
end

storage.read

-- @param key string
-- @return string|nil, string|nil
function storage.read(key) end

Reads the value from persistent storage by the given key. Returns data as string or nil if the value is not set in the storage.

On failure, it returns nil and an error message string.

Example

local value, err = storage.read("mykey")
if err ~= nil then
enapter.log("Cannot write read: " .. err, "error")
else
enapter.log("Value: " .. value)
end

storage.remove

-- @param key string
---@return string|nil
function storage.remove(key) end

Removes data from the persistent storage by the given key.

On failure, it returns an error message string.

Example

local err = storage.remove("mykey")
if err ~= nil then
enapter.log("Cannot remove value: " .. err, "error")
end

All Rights Reserved © 2025 Enapter AG.