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
commit5f86077aa2a9603b9928accd2f2d18f82bf40ad0 (patch)
tree90c54b1687e391173590ef727202ceeb70988fe0 /util
parent74f29daa298868c7c34f3e6d9fa5e6c18a296bdb (diff)
downloadprosody-5f86077aa2a9603b9928accd2f2d18f82bf40ad0.tar.gz
prosody-5f86077aa2a9603b9928accd2f2d18f82bf40ad0.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);