From 7070585c169306ee8226d23afa73e7f3f1251984 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Mar 2016 19:07:40 +0000 Subject: util.cache: Add head() and tail() methods (and tests) --- util/cache.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util') 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); -- cgit v1.2.3