aboutsummaryrefslogtreecommitdiffstats
path: root/util/cache.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-12-27 12:29:28 +0100
committerKim Alvefur <zash@zash.se>2015-12-27 12:29:28 +0100
commit0664d7ebf65a3ca356ec80ad4f706919ac745300 (patch)
tree50c569b3a43e2bf21301dba4606a02940a6ed127 /util/cache.lua
parentb3d8c070f940572d53e8bea734a7abef38411c56 (diff)
parentb50935a87c03246fac1541b275da4464a5b63b3b (diff)
downloadprosody-0664d7ebf65a3ca356ec80ad4f706919ac745300.tar.gz
prosody-0664d7ebf65a3ca356ec80ad4f706919ac745300.zip
Merge 0.10->trunk
Diffstat (limited to 'util/cache.lua')
-rw-r--r--util/cache.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/util/cache.lua b/util/cache.lua
index 72b74351..d3639b3f 100644
--- a/util/cache.lua
+++ b/util/cache.lua
@@ -51,19 +51,20 @@ function cache_methods:set(k, v)
return true;
end
-- Check whether we need to remove oldest k/v
+ local on_evict, evicted_key, evicted_value;
if self._count == self.size then
local tail = self._tail;
- local on_evict = self._on_evict;
- if on_evict then
- on_evict(tail.key, tail.value);
- end
+ on_evict, evicted_key, evicted_value = self._on_evict, tail.key, tail.value;
_remove(self, tail);
- self._data[tail.key] = nil;
+ self._data[evicted_key] = nil;
end
m = { key = k, value = v, prev = nil, next = nil };
self._data[k] = m;
_insert(self, m);
+ if on_evict and evicted_key then
+ on_evict(evicted_key, evicted_value, self);
+ end
return true;
end