Implemented eviction algorithm that samples a configurable number of keys with TTLs (default 20) at a configurable interval (default 100ms) and deletes the keys that are expired.

This commit is contained in:
Kelvin Mwinuka
2024-03-12 02:12:55 +08:00
parent 52b39d5b0f
commit f27a0dda79
6 changed files with 121 additions and 17 deletions

View File

@@ -153,9 +153,17 @@ func NewServer(opts Opts) *Server {
)
}
// TODO
// If eviction policy is not noeviction and the server is in standalone mode,
// start a goroutine to evict keys every 100 milliseconds.
// If eviction policy is not noeviction, start a goroutine to evict keys every 100 milliseconds.
if server.Config.EvictionPolicy != utils.NoEviction {
go func() {
for {
<-time.After(server.Config.EvictionInterval)
if err := server.evictKeysWithExpiredTTL(context.Background()); err != nil {
log.Println(err)
}
}
}()
}
return server
}