Module:CacheUtil

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

local h = {}

local p = {} function p.query(frame) local args = util_args.overwrite(true) 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 = util_args.overwrite(true) return cache.delete(args[1]) end

function p.set(frame) local args = util_args.overwrite(true) 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 = util_args.overwrite(true) return p._get(args[1]) end

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

function p.deleteAll(frame) local args = util_args.overwrite(true) 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 = util_args.overwrite(true) 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

return p