호출 방법
utils.getCachedInternal(cache, recordnil, func, ...)
의존성 utils.getCachedInternal을(를) 기록한 뒤 그 이름으로 호출하세요. 네임스페이스 호출은 self를 넘기지 않으므로 콜론 호출을 쓰거나 객체를 직접 넘기세요.
하는 일
utils.lua에서 제공하는 도우미입니다.
인수
| 이름 | 유형 | 하는 일 |
|---|---|---|
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. |
반환값
| 1 | ... | Every result of func, preserving nil positions and the return count; cached results are replayed on later calls with the same arguments. |
|---|
버전
기본 제공 도우미는 모든 버전에 등록됩니다. 다른 점은 읽는 게임 API이며, API가 없으면 도우미는 대체 동작을 하거나 이유와 함께 nil을 반환합니다.
게임 API를 직접 읽지 않습니다.
비공개 값 (Retail과 Forever)
Retail과 Forever에서는 게임이 애드온에 비공개 값을 넘깁니다. 이 도우미는 읽는 값을 확인하고(addon.Platform:CanReadValue), 비교할 수 없는 비공개 값 대신 restricted-value 같은 이유와 함께 nil을 반환합니다. nil은 거짓이 아니라 사용할 수 없음으로 취급하세요.
애드온에서 호출하는 방식
Functions.cache.getCachedreturn getCachedInternal(cache, true, func, ...)Functions.cache.getRetryCachedreturn getCachedInternal(cache, false, func, ...)
의존성
_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
소스
Functions/cache.lua, 57번째 줄. 게임에서는 읽기 전용이며, 복제하면 편집 가능한 사본이 생깁니다.
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)