github.com/decred/dcrlnd@v0.7.6/neutrinocache/cache.go (about)

     1  package cache
     2  
     3  import "fmt"
     4  
     5  var (
     6  	// ErrElementNotFound is returned when element isn't found in the cache.
     7  	ErrElementNotFound = fmt.Errorf("unable to find element")
     8  )
     9  
    10  // Cache represents a generic cache.
    11  type Cache interface {
    12  	// Put stores the given (key,value) pair, replacing existing value if
    13  	// key already exists. The return value indicates whether items had to
    14  	// be evicted to make room for the new element.
    15  	Put(key interface{}, value Value) (bool, error)
    16  
    17  	// Get returns the value for a given key.
    18  	Get(key interface{}) (Value, error)
    19  
    20  	// Len returns number of elements in the cache.
    21  	Len() int
    22  }
    23  
    24  // Value represents a value stored in the Cache.
    25  type Value interface {
    26  	// Size determines how big this entry would be in the cache. For
    27  	// example, for a filter, it could be the size of the filter in bytes.
    28  	Size() (uint64, error)
    29  }