模块:GameText/loaddata
跳到导航
跳到搜索
-- Note:
-- Storing json string into LuaCache and retrieveing data via `mw.text.jsonDecode(cache.get(cache_key_name))`
-- is at least 2x faster than storing lua table directly into LuaCache and retrieveing data via `cache.get(cache_key_name)`.
-- This is a bit weird.
local cache = mw.ext.LuaCache
return {
load = function(lang)
local status, result = pcall(function ()
return mw.text.jsonDecode(cache.get(':_gametext:data:'..lang), mw.text.JSON_PRESERVE_KEYS)
end)
if status then
return result
else
-- fallback
local jsonStr = require('Module:GameText/db-'..lang) or '{}'
-- cache it.
-- This cache can be purged by:
-- * purge `Module:GameText/db-<lang>` or `Module:GameText/db-<lang>/doc` page
-- * lua code: `require('Module:GameText/loaddata').purge(<lang>)`
-- * template code: `{{#invoke:GameText|purge|lang=<lang>}}`
cache.set( ':_gametext:data:'..lang, jsonStr)
end
end,
purge = function(lang)
cache.delete(':_gametext:data:'..lang)
end,
}
分类:
- 无文档的模块