Simplifying memory sleep logic

master
Frederick F. Kautz IV 10 years ago
parent 362305d898
commit 8fcb697844
  1. 10
      pkg/storage/drivers/memory/memory.go

@ -484,13 +484,10 @@ func (memory *memoryDriver) expireObjects() {
return
}
var keysToRemove []string
if len(memory.objectMetadata) > 0 {
memory.lock.RLock()
var earliest time.Time
empty := true
for key, object := range memory.objectMetadata {
if empty {
empty = false
}
if time.Now().Add(-memory.expiration).After(object.metadata.Created) {
keysToRemove = append(keysToRemove, key)
} else {
@ -505,13 +502,12 @@ func (memory *memoryDriver) expireObjects() {
memory.objects.Remove(key)
}
memory.lock.Unlock()
if empty {
time.Sleep(memory.expiration)
} else {
sleepFor := earliest.Sub(time.Now())
if sleepFor > 0 {
time.Sleep(sleepFor)
}
} else {
time.Sleep(memory.expiration)
}
}
}

Loading…
Cancel
Save