// refreshAsync reloads value in a go routine or using custom executor if defined.
func (c *localCache) refreshAsync(en *entry) bool {
if en.setLoading(true) {
// Only do refresh if it isn't running.
if c.reloader == nil {
go c.refresh(en)
} else {
c.reload(en)
}
return true
}
return false
}
Inspecting the code, I find that the loader refresh in a new go routine, while reloader reload in the current routine. Why the difference? Should we define the loader load in new go routine, or current routine?
reloader is a user-defined way to refresh cache entries, e.g. using a pool to avoid creating a new goroutine for each refresh.
loader is a cache loader function, must be synchronous.
Inspecting the code, I find that the
loader
refresh in a new go routine, whilereloader
reload in the current routine. Why the difference? Should we define the loader load in new go routine, or current routine?