Riferimento › Riferimento delle funzioni › utils

utils.getCachedInternal

dipendenza

Chiamala come

utils.getCachedInternal(cache, recordnil, func, ...)

Registra la dipendenza utils.getCachedInternal, poi chiamala con quel nome. Una chiamata con spazio dei nomi non passa self: usa una chiamata con i due punti o passa tu l'oggetto.

Cosa fa

Funzione di supporto inclusa da utils.lua.

Argomenti

NomeTipoCosa fa
cachetable | nilEvaluation-pass cache, or nil to call func directly without caching.
recordnilbooleanTrue to cache every result, including all-nil ones (getCached); false to cache only results with a non-nil value (getRetryCached).
funcfunction | stringFunction to call, or the name of a global function; anything else returns nothing.
...anyArguments forwarded to func and used as the exact cache key; a restricted or NaN argument bypasses the cache.

Valori restituiti

1...Every result of func, preserving nil positions and the return count; cached results are replayed on later calls with the same arguments.

Edizioni

Le funzioni di supporto integrate sono registrate su ogni edizione. Ciò che cambia è l'API di gioco che leggono; dove ne manca una, la funzione di supporto ripiega su un'alternativa o restituisce nil con un motivo.

Non legge direttamente alcuna API di gioco.

Valori segreti (Retail e Forever)

Su Retail e Forever il gioco fornisce agli addon valori segreti. Questa funzione di supporto controlla ciò che legge (addon.Platform:CanReadValue) e restituisce nil con un motivo come restricted-value invece di un valore segreto che non può confrontare. Considera nil come non disponibile, non come false.

Come la chiama l'addon

Dipendenze

Sorgente

Functions/cache.lua, riga 57. Nel gioco è in sola lettura; Duplica crea una copia modificabile.

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)

Torna a Riferimento delle funzioni