Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 3: | Строка 3: | ||
local cachedData = nil | local cachedData = nil | ||
local loadCount = 0 | local loadCount = 0 | ||
local cache = mw.ext.LuaCache and mw.ext.LuaCache.get("entity_data_cache") | |||
local function loadData(filePath) | local function loadData(filePath) | ||
| Строка 8: | Строка 10: | ||
return cachedData | return cachedData | ||
end | end | ||
if cache then | |||
local cachedContent = cache:get(filePath) | |||
if cachedContent then | |||
cachedData = mw.text.jsonDecode(cachedContent) | |||
return cachedData | |||
end | |||
end | |||
loadCount = loadCount + 1 | loadCount = loadCount + 1 | ||
local page = mw.title.new(filePath) | local page = mw.title.new(filePath) | ||
local content = page and page:getContent() | local content = page and page:getContent() | ||
cachedData = content and mw.text.jsonDecode(content) or nil | cachedData = content and mw.text.jsonDecode(content) or nil | ||
if cachedData and cache then | |||
cache:set(filePath, content, 3600) | |||
end | |||
return cachedData | return cachedData | ||
end | end | ||