github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/infra/acache/fetcher.go (about)

     1  package acache
     2  
     3  type Fetcher interface {
     4  	Fetch(key string) (any, error)
     5  }
     6  
     7  type BatchFetcher interface {
     8  	Fetcher
     9  	BatchSize() int
    10  	BatchFetch(keys []string) (map[string]any, error)
    11  }
    12  
    13  // FuncFetcher is a function that implements the interface Fetcher.
    14  type FuncFetcher func(key string) (any, error)
    15  
    16  func (f FuncFetcher) Fetch(key string) (any, error) {
    17  	return f(key)
    18  }