Comparison

spec/util_cache_spec.lua @ 13175:bbdaa770b955

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)
author Kim Alvefur <zash@zash.se>
date Fri, 30 Jun 2023 22:01:55 +0200
parent 13174:8ec7b7d6556f
comparison
equal deleted inserted replaced
13174:8ec7b7d6556f 13175:bbdaa770b955
388 c:resize(3); 388 c:resize(3);
389 assert.same({"v5", "v4", "v3"}, vs(c)); 389 assert.same({"v5", "v4", "v3"}, vs(c));
390 end); 390 end);
391 391
392 it("eviction stuff", function () 392 it("eviction stuff", function ()
393 local c; 393 local c = cache.new(4, function(_k,_v,c)
394 c = cache.new(4, function(_k,_v)
395 if c.size < 10 then 394 if c.size < 10 then
396 c:resize(c.size*2); 395 c:resize(c.size*2);
397 end 396 end
398 end) 397 end)
399 for i = 1,20 do 398 for i = 1,20 do