Storing function return value

I’ve made a function that returns a string and the function is being ran continuously in a HUDPaint hook. Because the return value doesn’t change too often I want to be able to store the variable instead of calculating over and over but I’m unsure how.



local cache = {}

function CalculateSomething(input)
	if cache[input] then
		return cache[input]
	end

	local calculated = input * 5 / 10 + 8
	cache[input] = calculated

	return calculated
end


This is just an example. Modify at will.