mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-21 06:59:24 +08:00
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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user