github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/cache/common.go (about)

     1  package cache
     2  
     3  import (
     4  	"github.com/prysmaticlabs/prysm/shared/params"
     5  	"k8s.io/client-go/tools/cache"
     6  )
     7  
     8  var (
     9  	// maxCacheSize is 4x of the epoch length for additional cache padding.
    10  	// Requests should be only accessing committees within defined epoch length.
    11  	maxCacheSize = uint64(4 * params.BeaconConfig().SlotsPerEpoch)
    12  )
    13  
    14  // trim the FIFO queue to the maxSize.
    15  func trim(queue *cache.FIFO, maxSize uint64) {
    16  	for s := uint64(len(queue.ListKeys())); s > maxSize; s-- {
    17  		_, err := queue.Pop(popProcessNoopFunc)
    18  		if err != nil {
    19  			// popProcessNoopFunc never returns an error, but we handle this anyway to make linter
    20  			// happy.
    21  			return
    22  		}
    23  	}
    24  }
    25  
    26  // popProcessNoopFunc is a no-op function that never returns an error.
    27  func popProcessNoopFunc(_ interface{}) error {
    28  	return nil
    29  }