Module: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- ` or `Module:GameText/db- /doc` page -- * lua code: `require('Module:GameText/loaddata').purge` -- * template code: `` cache.set( ':_gametext:data:'..lang, jsonStr) end end, purge = function(lang) cache.delete(':_gametext:data:'..lang) end, }