Allow Transform Functions to Return the Expiration Time for UpdateAsync in SortedMaps as Well as Get the Remaining Expiration Time

The newly added SortedMaps have a handy argument in their SetAsync and UpdateAsync methods called expiration time. This value sets the lifetime of stored values, so that when it runs out, the value gets cleared, allowing proper data management for unresponsive servers. My issue is with how the UpdateAsync method is implemented.

As a Roblox developer, it is impossible to configure the expiration time depending on what value gets parsed to the transform function. UpdateAsync is a method that gets the latest stored value, parses it to the transform function, which then returns the new value you want to set. I believe transform functions should have a 2nd optional returned value which overwrites the expiration time. This would allow developers to create modular and clean systems without complex workarounds involving GetAsync calls. It would also be nice if we could get the remaining expiration time of values as a 2nd argument.

Current implementation:

local funcTransform = function(valOld)
    -- no way to modify the expiration time
    if valOld <10 then
        return valOld+5
    else
        return valOld+2
    end
end

SortedMap:UpdateAsync(Key, funcTransform, ExpirationTime)

What Iā€™d like to see:

local funcTransform = function(valOld, expirationRemaining)
    if valOld <10 then
        return valOld+5, 10 -- clear in 10 seconds
    else
        return valOld+2 -- use ExpirationTime value parsed below
    end
end

SortedMap:UpdateAsync(Key, funcTransform, ExpirationTime) -- ExpirationTime is used as a default value if no 2nd value is returned
5 Likes