aboutsummaryrefslogtreecommitdiffstats
path: root/util/cache.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-06-30 22:01:55 +0200
committerKim Alvefur <zash@zash.se>2023-06-30 22:01:55 +0200
commit915ef3a222a4b2b1472fe73dc88f7ce4e4a9420b (patch)
tree981fba8364e21dc156d4ab2267f07b4a2a2de313 /util/cache.lua
parent29b6ed4f0a40f0f595d21537e1308f744b9a4907 (diff)
downloadprosody-915ef3a222a4b2b1472fe73dc88f7ce4e4a9420b.tar.gz
prosody-915ef3a222a4b2b1472fe73dc88f7ce4e4a9420b.zip
util.cache: Pass cache itself to eviction callback
Simplifies access to the cache without moving code around a lot given the currently common pattern of local some_cache = cache.new(size, function(k,v) end)
Diffstat (limited to 'util/cache.lua')
-rw-r--r--util/cache.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/util/cache.lua b/util/cache.lua
index a72a535f..e1873cc8 100644
--- a/util/cache.lua
+++ b/util/cache.lua
@@ -55,7 +55,7 @@ function cache_methods:set(k, v)
local tail = self._tail;
local on_evict, evicted_key, evicted_value = self._on_evict, tail.key, tail.value;
- local do_evict = on_evict and on_evict(evicted_key, evicted_value);
+ local do_evict = on_evict and on_evict(evicted_key, evicted_value, self);
if do_evict == false then
-- Cache is full, and we're not allowed to evict
@@ -129,7 +129,7 @@ function cache_methods:resize(new_size)
while self._count > new_size do
local tail = self._tail;
local evicted_key, evicted_value = tail.key, tail.value;
- if on_evict ~= nil and (on_evict == false or on_evict(evicted_key, evicted_value) == false) then
+ if on_evict ~= nil and (on_evict == false or on_evict(evicted_key, evicted_value, self) == false) then
-- Cache is full, and we're not allowed to evict
return false;
end