func()

in pkg/cached/cached.go [114:135]


func (r *CachedReader) updateCache(p []byte, offset int64) {
	// This is lazy so just update if the data is contiguous.
	// Check boundaries with a read lock first.
	r.cache.lock.RLock()
	if int64(len(r.cache.cache)) < offset ||
		int64(cap(r.cache.cache)) <= offset {
		r.cache.lock.RUnlock()
		return
	}
	r.cache.lock.RUnlock()

	r.cache.lock.Lock()
	defer r.cache.lock.Unlock()
	overlap := len(r.cache.cache) - int(offset)
	n := len(p) - overlap
	if overlap >= 0 && n > 0 {
		if len(r.cache.cache)+n > cap(r.cache.cache) {
			n = cap(r.cache.cache) - len(r.cache.cache)
		}
		r.cache.cache = append(r.cache.cache, p[overlap:overlap+n]...)
	}
}