aboutsummaryrefslogtreecommitdiffstats
path: root/util/cache.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-05-22 20:07:20 +0100
committerMatthew Wild <mwild1@gmail.com>2016-05-22 20:07:20 +0100
commit4ba59d52f26e0fc37af41eecc501e21cd6b0aff4 (patch)
tree3473c4c4cae6c0f24a20b75f573512f2e5ebc36c /util/cache.lua
parent3d6224e543c6018920666bc4c7a52ca1cc3ab591 (diff)
parent83eb775cb0b7287da70b8203cf7acfd5fd4b9c26 (diff)
downloadprosody-4ba59d52f26e0fc37af41eecc501e21cd6b0aff4.tar.gz
prosody-4ba59d52f26e0fc37af41eecc501e21cd6b0aff4.zip
Merge 0.10->trunk
Diffstat (limited to 'util/cache.lua')
-rw-r--r--util/cache.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/util/cache.lua b/util/cache.lua
index 54f3e10b..44bbfe30 100644
--- a/util/cache.lua
+++ b/util/cache.lua
@@ -116,6 +116,28 @@ function cache_methods:tail()
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);