Aufruf als
utils.getCachedInternal(cache, recordnil, func, ...)
Erfassen Sie die Abhängigkeit utils.getCachedInternal und rufen Sie sie dann unter diesem Namen auf. Ein Aufruf über den Namensraum übergibt kein self: Verwenden Sie einen Doppelpunkt-Aufruf oder übergeben Sie das Objekt selbst.
Was sie bewirkt
Mitgelieferte Hilfsfunktion aus utils.lua.
Argumente
| Name | Typ | Was sie bewirkt |
|---|---|---|
cache | table | nil | Evaluation-pass cache, or nil to call func directly without caching. |
recordnil | boolean | True to cache every result, including all-nil ones (getCached); false to cache only results with a non-nil value (getRetryCached). |
func | function | string | Function to call, or the name of a global function; anything else returns nothing. |
... | any | Arguments forwarded to func and used as the exact cache key; a restricted or NaN argument bypasses the cache. |
Rückgabewerte
| 1 | ... | Every result of func, preserving nil positions and the return count; cached results are replayed on later calls with the same arguments. |
|---|
Editionen
Integrierte Hilfsfunktionen werden auf jeder Edition registriert. Unterschiedlich ist die Spiel-API, die sie lesen; fehlt eine, weicht die Hilfsfunktion aus oder gibt nil mit einem Grund zurück.
Sie liest keine Spiel-API direkt.
Geheime Werte (Retail und Forever)
Auf Retail und Forever übergibt das Spiel Addons geheime Werte. Diese Hilfsfunktion prüft, was sie liest (addon.Platform:CanReadValue), und gibt statt eines geheimen Werts, den sie nicht vergleichen kann, nil mit einem Grund wie restricted-value zurück. Behandeln Sie nil als nicht verfügbar, nicht als false.
Wie das Addon sie aufruft
Functions.cache.getCachedreturn getCachedInternal(cache, true, func, ...)Functions.cache.getRetryCachedreturn getCachedInternal(cache, false, func, ...)
Abhängigkeiten
_G(builtin:utils.lua:_G)cacheHits(builtin:utils.lua:cacheHits)cacheMisses(builtin:utils.lua:cacheMisses)cachedResult(builtin:utils.lua:cachedResult)nilArgument(builtin:utils.lua:nilArgument)packResults→utils.packResults
Quelle
Functions/cache.lua, Zeile 57. Im Spiel schreibgeschützt; Duplizieren erstellt eine bearbeitbare Kopie.
utils.getCachedInternal(cache, recordnil, func, ...)
if type(func) == 'string' then func = _G[func] end
if type(func) ~= 'function' then return end
if cache == nil then return func(...) end
-- Exact keys preserve argument types, identity and arity. Hashing concatenated
-- strings allowed unrelated observations to collide, even for numeric IDs.
local args, count = { ... }, select('#', ...)
for i = 1, count do
local value = args[i]
if addon.Platform and addon.Platform.CanReadValue and not addon.Platform:CanReadValue(value) then
return func(...)
end
if type(value) == 'number' and value ~= value then return func(...) end
if value == nil then args[i] = nilArgument end
end
local node = cache[func]
for i = 1, count do
if not node then break end
node = node[args[i]]
end
local result = node and node[cachedResult]
if result then
cacheHits = cacheHits + 1
return unpack(result, 1, result.n)
end
cacheMisses = cacheMisses + 1
result = packResults(func(...))
local store = recordnil
if not store then
-- Inspect the packed keys, not potentially restricted return values.
for key in pairs(result) do
if type(key) == 'number' then store = true; break end
end
end
if store then
-- Retry misses and thrown calls must not accumulate empty paths.
if not cache[func] then cache[func] = {} end
node = cache[func]
for i = 1, count do
local key = args[i]
if not node[key] then node[key] = {} end
node = node[key]
end
node[cachedResult] = result
end
return unpack(result, 1, result.n)