github.com/thanos-io/thanos@v0.32.5/internal/cortex/chunk/cache/memcached_client_test.go (about)

     1  // Copyright (c) The Cortex Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package cache_test
     5  
     6  import (
     7  	"sync"
     8  
     9  	"github.com/bradfitz/gomemcache/memcache"
    10  )
    11  
    12  type mockMemcache struct {
    13  	sync.RWMutex
    14  	contents map[string][]byte
    15  }
    16  
    17  func newMockMemcache() *mockMemcache {
    18  	return &mockMemcache{
    19  		contents: map[string][]byte{},
    20  	}
    21  }
    22  
    23  func (m *mockMemcache) GetMulti(keys []string) (map[string]*memcache.Item, error) {
    24  	m.RLock()
    25  	defer m.RUnlock()
    26  	result := map[string]*memcache.Item{}
    27  	for _, k := range keys {
    28  		if c, ok := m.contents[k]; ok {
    29  			result[k] = &memcache.Item{
    30  				Value: c,
    31  			}
    32  		}
    33  	}
    34  	return result, nil
    35  }
    36  
    37  func (m *mockMemcache) Set(item *memcache.Item) error {
    38  	m.Lock()
    39  	defer m.Unlock()
    40  	m.contents[item.Key] = item.Value
    41  	return nil
    42  }