mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(resource/cache): new cache event
Rather than sending a bulk update of cache, trigger different events for each key.
This commit is contained in:
10
resource/cache/client.lua
vendored
10
resource/cache/client.lua
vendored
@@ -24,12 +24,10 @@ function cache:getVehicle()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local update = {}
|
|
||||||
|
|
||||||
function cache:set(key, value)
|
function cache:set(key, value)
|
||||||
if value ~= self[key] then
|
if value ~= self[key] then
|
||||||
self[key] = value
|
self[key] = value
|
||||||
update[key] = value
|
TriggerEvent(('ox_lib:cache:%s'):format(key), value)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -38,12 +36,6 @@ CreateThread(function()
|
|||||||
while true do
|
while true do
|
||||||
cache:set('ped', PlayerPedId())
|
cache:set('ped', PlayerPedId())
|
||||||
cache:getVehicle()
|
cache:getVehicle()
|
||||||
|
|
||||||
if next(update) then
|
|
||||||
TriggerEvent('ox_lib:updateCache', update)
|
|
||||||
table.wipe(update)
|
|
||||||
end
|
|
||||||
|
|
||||||
Wait(100)
|
Wait(100)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user