forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request grafana#994 from grafana/batch-memcache
Batch memcache requests
- Loading branch information
Showing
4 changed files
with
308 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cache_test | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/bradfitz/gomemcache/memcache" | ||
) | ||
|
||
type mockMemcache struct { | ||
sync.RWMutex | ||
contents map[string][]byte | ||
} | ||
|
||
func newMockMemcache() *mockMemcache { | ||
return &mockMemcache{ | ||
contents: map[string][]byte{}, | ||
} | ||
} | ||
|
||
func (m *mockMemcache) GetMulti(keys []string) (map[string]*memcache.Item, error) { | ||
m.RLock() | ||
defer m.RUnlock() | ||
result := map[string]*memcache.Item{} | ||
for _, k := range keys { | ||
if c, ok := m.contents[k]; ok { | ||
result[k] = &memcache.Item{ | ||
Value: c, | ||
} | ||
} | ||
} | ||
return result, nil | ||
} | ||
|
||
func (m *mockMemcache) Set(item *memcache.Item) error { | ||
m.Lock() | ||
defer m.Unlock() | ||
m.contents[item.Key] = item.Value | ||
return nil | ||
} |
Oops, something went wrong.