local registry = {} LimitedCache = { new = function(self,max) if(not max or type(max) ~= "number") then error("You must provide a cache size",2) end local o = setmetatable({},self) registry[o] = {max = max} return o end, __newindex = function(t,k,v) local mt = registry[t] if(table.getn(mt) == mt.max) then t[table.remove(mt,1)] = nil end table.insert(mt,k) rawset(t,k,v) end, }