From c1c5626df365d99d278b82d2ef0523622f90e6af Mon Sep 17 00:00:00 2001 From: JericoFX Date: Mon, 12 May 2025 14:31:33 -0300 Subject: [PATCH] add update function to cache --- lib/cache/shared/cache.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/cache/shared/cache.lua b/lib/cache/shared/cache.lua index c6fe0b1..05b5359 100644 --- a/lib/cache/shared/cache.lua +++ b/lib/cache/shared/cache.lua @@ -139,6 +139,22 @@ function Cache.OnChange(name, onChange) cache.OnChange[#cache.OnChange + 1] = onChange end +---@param name string +---@param newValue any +function Cache.Update(name, newValue) + assert(name, "Cache name is required.") + local _name = tostring(name) + local cache = Cache.Caches[_name] + assert(cache, "Cache with name '" .. _name .. "' does not exist.") + local oldValue = cache.Value + if oldValue ~= newValue then + cache.Value = newValue + for i = 1, #cache.OnChange do + cache.OnChange[i](newValue, oldValue) + end + end +end + ---@param name string function Cache.Remove(name) assert(name, "Cache name is required.")