func (c *DirentCache) Add(d *Dirent) {
	if c == nil || c.maxSize == 0 {
		return
	}

	c.mu.Lock()
	if c.contains(d) {
		// d is already in cache. Bump it to the front.
		// currentSize and refCount are unaffected.
		c.list.Remove(d)
		c.list.PushFront(d)
		c.mu.Unlock()
		return
	}

	// First check against the global limit.
	for c.limit != nil && !c.limit.tryInc() {
		if c.currentSize == 0 {
			// If the global limit is reached, but there is nothing more to drop from
			// this cache, there is not much else to do.
			c.mu.Unlock()
			return
		}
		c.remove(c.list.Back())
	}

	// d is not in cache. Add it and take a reference.
	c.list.PushFront(d)
	d.IncRef()
	c.currentSize++

	c.maybeShrink()

	c.mu.Unlock()
}
// Add adds the element to the cache and increments the refCount. If the
// argument is already in the cache, it is moved to the front. An element is
// removed from the back if the cache is over capacity.
Add adds the element to the cache and increments the refCount. If the
argument is already in the cache, it is moved to the front. An element is
removed from the back if the cache is over capacity.
// Add adds the element to the cache and increments the refCount . If the // argument is already in the cache it is moved to the front . An element is // removed from the back if the cache is over capacity .
func (c *DirentCache) Add(d *Dirent) {
	if c == nil || c.maxSize == 0 {
		return
	}
	c.mu.Lock()
	if c.contains(d) {
		c.list.Remove(d)
		c.list.PushFront(d)
		c.mu.Unlock()
		return
	}
	for c.limit != nil && !c.limit.tryInc() {
		if c.currentSize == 0 {
			c.mu.Unlock()
			return
		}
		c.remove(c.list.Back())
	}
	c.list.PushFront(d)
	d.IncRef()
	c.currentSize++
	c.maybeShrink()
	c.mu.Unlock()
}
func ( c * DirentCache ) Add ( d * Dirent ) { if c == nil || c . maxSize == 0 { return } c . mu . Lock ( ) if c . contains ( d ) { c . list . Remove ( d ) c . list . PushFront ( d ) c . mu . Unlock ( ) return } for c . limit != nil && ! c . limit . tryInc ( ) { if c . currentSize == 0 { c . mu . Unlock ( ) return } c . remove ( c . list . Back ( ) ) } c . list . PushFront ( d ) d . IncRef ( ) c . currentSize ++ c . maybeShrink ( ) c . mu . Unlock ( ) }
Add adds the element to the cache and increments the refCount.
Add adds the element to the cache and increments the refCount .
// d is already in cache. Bump it to the front. // currentSize and refCount are unaffected. // First check against the global limit. // If the global limit is reached, but there is nothing more to drop from // this cache, there is not much else to do. // d is not in cache. Add it and take a reference.