Module:CacheUtil

-- Code from: https://lol.fandom.com/wiki/Module:CacheUtil -- Invoked by JS at: TODO

-- local util_args = require('Module:ArgsUtil') local getArgs = require('Module:Arguments').getArgs local cache = require('mw.ext.LuaCache')

local h = {}

local p = {} function p.query(frame) local args = getArgs( mw.getCurrentFrame ) local data = cache.get(args[1]) if not data then return ('Cache does not exist for %s'):format(args[1]) end local tbl = {} for k, v in pairs(data) do tbl[#tbl+1] = k .. ', ' .. tostring(v) end return table.concat(tbl,' ') end

function p.delete(frame) local args = getArgs( mw.getCurrentFrame ) return cache.delete(args[1]) end

function p.set(frame) local args = getArgs( mw.getCurrentFrame ) return p._set(args[1], args[2]) end

function p._set(key, value) return cache.set(key, value) end

function p.get(frame) local args = getArgs( mw.getCurrentFrame ) return p._get(args[1]) end

function p._get(key) local ret = cache.get(key) return ret end

function p.deleteAll(frame) local args = getArgs( mw.getCurrentFrame ) local data = require('Module:' .. args[1]) local prefix = args.prefix or '' for key, _ in pairs(data) do cache.delete(prefix .. key) end end

function p.resetAll(frame) local args = getArgs( mw.getCurrentFrame ) p.deleteAll(frame) local data = require('Module:' .. args[1]) local f = require('Module:' .. args.module)[args.f or 'main'] for key, _ in pairs(data) do		f(key) end end

function p.resetAllSimple(frame) local args = getArgs( frame or mw.getCurrentFrame ) p.deleteAll(frame) local data = require('Module:' .. args[1]) for key, val in pairs(data) do		cache.set(args.prefix..key, val) end end

return p