aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-03-17 19:07:40 +0000
committerMatthew Wild <mwild1@gmail.com>2016-03-17 19:07:40 +0000
commit7070585c169306ee8226d23afa73e7f3f1251984 (patch)
tree90c54b1687e391173590ef727202ceeb70988fe0 /util
parent379b127825254207f3163b6c2a00e0676fd6a136 (diff)
downloadprosody-7070585c169306ee8226d23afa73e7f3f1251984.tar.gz
prosody-7070585c169306ee8226d23afa73e7f3f1251984.zip
util.cache: Add head() and tail() methods (and tests)
Diffstat (limited to 'util')
-rw-r--r--util/cache.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/cache.lua b/util/cache.lua
index d3639b3f..e53bf4bf 100644
--- a/util/cache.lua
+++ b/util/cache.lua
@@ -92,6 +92,18 @@ function cache_methods:count()
return self._count;
end
+function cache_methods:head()
+ local head = self._head;
+ if not head then return nil, nil; end
+ return head.key, head.value;
+end
+
+function cache_methods:tail()
+ local tail = self._tail;
+ if not tail then return nil, nil; end
+ return tail.key, tail.value;
+end
+
local function new(size, on_evict)
size = assert(tonumber(size), "cache size must be a number");
size = math.floor(size);