# HG changeset patch # User Matthew Wild # Date 1463944040 -3600 # Node ID 6bf4c227c8f3e6953adc899f2e7fb7f466463d67 # Parent ff74188488ab2f53e458844f278baea01408d3a4# Parent 8603b16e85c7ee19bb9480cf4cffdf9b5a4891f2 Merge 0.10->trunk diff -r ff74188488ab -r 6bf4c227c8f3 util/cache.lua --- a/util/cache.lua Sun May 22 20:06:51 2016 +0100 +++ b/util/cache.lua Sun May 22 20:07:20 2016 +0100 @@ -116,6 +116,28 @@ return tail.key, tail.value; end +function cache_methods:table() + if not self.proxy_table then + self.proxy_table = setmetatable({}, { + __index = function (t, k) + return self:get(k); + end; + __newindex = function (t, k, v) + if not self:set(k, v) then + error("failed to insert key into cache - full"); + end + end; + __pairs = function (t) + return self:items(); + end; + __len = function (t) + return self:count(); + end; + }); + end + return self.proxy_table; +end + local function new(size, on_evict) size = assert(tonumber(size), "cache size must be a number"); size = math.floor(size);