Module:Tr/loaddata
Jump to navigation
Jump to search
If the {{Tr}} cached data needs to be purged, purge Module:Tr/loaddata or invoke {{#invoke:Tr|purge|lang=<lang code>}}
in the case if you need to purge data for the specific language.
-- Note:
-- It seems that objects/lists stored via luacache have a limit on the number of entities, which is about 8k.
-- Any object/list which has more then 8k entities or having such a large sub-object/sub-list will be truncated.
-- Therefore, we encode the data into a string to get around this problem.
local cache = mw.ext.LuaCache
return {
load = function(lang)
local status, result = pcall(function ()
return mw.text.jsonDecode(cache.get('tr__database-'..lang))
end)
if status then
return result
else
-- fallback
local info = require('Module:Tr/db-'..lang) -- return table of mw.loadData() has a metatable, can not be used for cache.set and mw.loadData.
-- add on wiki language list
info.onWikiLangList = { ['ko'] = true }
-- cache it.
-- This cache can be purged by:
-- * purge Module:tr/db-<lang> or Module:tr/db-<lang>/doc page
-- * lua code: require('Module:Tr/loaddata').purge(<lang>)
-- * template code: {{#invoke:tr|purge|lang=<lang>}}
cache.set( 'tr__database-'..lang, mw.text.jsonEncode(info))
return info
end
end,
purge = function(lang)
cache.delete( 'tr__database-'..lang)
end
}