@@ -8,6 +8,7 @@ local http_util = require "http.util"
88
99local store_methods = {
1010 time = function () return os.time () end ;
11+ max_items = (1e999 );
1112}
1213
1314local store_mt = {
@@ -25,12 +26,14 @@ local function new_store()
2526 return setmetatable ({
2627 domains = {};
2728 expiry_heap = binaryheap .minUnique ();
29+ n_items = 0 ;
2830 }, store_mt )
2931end
3032
3133function store_methods :clone ()
3234 local r = new_store ()
3335 r .time = rawget (self , " time" )
36+ r .n_items = rawget (self , " n_items" )
3437 r .expiry_heap = binaryheap .minUnique ()
3538 for host , item in pairs (self .domains ) do
3639 r .domains [host ] = item
@@ -63,6 +66,12 @@ function store_methods:store(host, directives)
6366 local old_item = self .domains [host ]
6467 if old_item then
6568 self .expiry_heap :remove (old_item )
69+ else
70+ local n_items = self .n_items
71+ if n_items >= self .max_items then
72+ return false
73+ end
74+ self .n_items = n_items + 1
6675 end
6776 local expires = now + max_age
6877 local item = setmetatable ({
@@ -81,6 +90,7 @@ function store_methods:remove(host)
8190 if item then
8291 self .expiry_heap :remove (item )
8392 self .domains [host ] = nil
93+ self .n_items = self .n_items - 1
8494 end
8595 return true
8696end
@@ -120,6 +130,7 @@ function store_methods:clean()
120130 while self :clean_due () < now do
121131 local item = self .expiry_heap :pop ()
122132 self .domains [item .host ] = nil
133+ self .n_items = self .n_items - 1
123134 end
124135 return true
125136end
0 commit comments