muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Other
2.11k stars 518 forks source link

AfterFunc with go #24

Open learnergo opened 5 years ago

learnergo commented 5 years ago
if smallestDuration > 0 {
        table.cleanupTimer = time.AfterFunc(smallestDuration, func() {
            go table.expirationCheck()
        })
}

AfterFunc creates a new goroute.Is it necessary to use 'go' in 'AfterFunc'

muesli commented 5 years ago

I think it's preferred because otherwise cleaning up the table (which can be a costly routine) would block the caller.

learnergo commented 5 years ago

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
        go table.expirationCheck()
}
Nassue commented 5 years ago

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
      go table.expirationCheck()
}

it will run more times, not just run once for smallestDuration

learnergo commented 5 years ago

I think "go" should be here:

if item.lifeSpan > 0 && (expDur == 0 || item.lifeSpan < expDur) {
        go table.expirationCheck()
}

it will run more times, not just run once for smallestDuration

??