2026-04-14 17:41:39 +02:00

34 lines
817 B
Lua

--- Desencrypted By PrejuicioX
local cacheStorage = {}
function SaveCache(key, data, ttl)
local expirationTime = GetGameTimer() + (ttl or 3000)
cacheStorage[key] = {
data = data,
maxAge = expirationTime
}
end
function WipeCache(key)
cacheStorage[key] = nil
end
function UseCache(key, fetchFunction, ttl)
local cachedEntry = cacheStorage[key]
local currentTime = GetGameTimer()
-- Check if cache exists and is still valid
if not cachedEntry or cachedEntry.maxAge < currentTime then
-- Cache miss or expired - fetch fresh data
local result = {fetchFunction()}
SaveCache(key, result, ttl)
return table.unpack(result)
end
-- Cache hit - return cached data
return table.unpack(cachedEntry.data)
end
--- Desencrypted By PrejuicioX