cache icon indicating copy to clipboard operation
cache copied to clipboard

Should reloader load in a go routine or not?

Open juvenn opened this issue 2 years ago • 1 comments

// 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?

juvenn avatar Feb 27 '22 07:02 juvenn

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.

nqv avatar Apr 12 '22 19:04 nqv