github.com/sequix/cortex@v1.1.6/pkg/chunk/cache/mock.go (about)

     1  package cache
     2  
     3  import (
     4  	"context"
     5  	"sync"
     6  )
     7  
     8  type mockCache struct {
     9  	sync.Mutex
    10  	cache map[string][]byte
    11  }
    12  
    13  func (m *mockCache) Store(_ context.Context, keys []string, bufs [][]byte) {
    14  	m.Lock()
    15  	defer m.Unlock()
    16  	for i := range keys {
    17  		m.cache[keys[i]] = bufs[i]
    18  	}
    19  }
    20  
    21  func (m *mockCache) Fetch(ctx context.Context, keys []string) (found []string, bufs [][]byte, missing []string) {
    22  	m.Lock()
    23  	defer m.Unlock()
    24  	for _, key := range keys {
    25  		buf, ok := m.cache[key]
    26  		if ok {
    27  			found = append(found, key)
    28  			bufs = append(bufs, buf)
    29  		} else {
    30  			missing = append(missing, key)
    31  		}
    32  	}
    33  	return
    34  }
    35  
    36  func (m *mockCache) Stop() error {
    37  	return nil
    38  }
    39  
    40  // NewMockCache makes a new MockCache
    41  func NewMockCache() Cache {
    42  	return &mockCache{
    43  		cache: map[string][]byte{},
    44  	}
    45  }