Replace time-dependent cache limiting with LRU

To keep memory usage as constant as possible, the previous cache
purging at periodic time intervals has been replaced by an LRU that
discards the oldest string when the capacity of the cache is reached.

Also fixed some formatting and commenting issues, and added better
testing for the rate limiter.

Signed-off-by: Wendi Yu <wendi.yu@yahoo.ca>
This commit is contained in:
Wendi Yu
2020-05-07 13:54:45 -06:00
parent ca6675386b
commit 8a94ccc5a2
5 changed files with 84 additions and 52 deletions

View File

@@ -193,15 +193,15 @@ type testNode struct {
func newNode(t *testing.T, prefix string, https *httptest.Server, weirdPrefs bool) testNode {
t.Helper()
ulogfe := func(fmt string, args ...interface{}) {
logfe := func(fmt string, args ...interface{}) {
t.Logf(prefix+".e: "+fmt, args...)
}
logfe := logger.RateLimitedFn(ulogfe, 1, 1)
logfe := logger.RateLimitedFn(logfe, 1, 1)
ulogf := func(fmt string, args ...interface{}) {
logf := func(fmt string, args ...interface{}) {
t.Logf(prefix+": "+fmt, args...)
}
logf := logger.RateLimitedFn(ulogf, 1, 1)
logf := logger.RateLimitedFn(logf, 1, 1, 100)
var err error
httpc := https.Client()

View File

@@ -40,7 +40,7 @@ func TestRunMultipleAccepts(t *testing.T) {
t.Logf(format, args...)
}
logf := logger.RateLimitedFn(ulogf, 1, 1)
logf := logger.RateLimitedFn(ulogf, 1, 1, 100)
connect := func() {
for i := 1; i <= 2; i++ {