mirror of https://github.com/grafana/loki
Update vendored dskit (#8155)
**What this PR does / why we need it**:
The Changelog diff between the two commits is
3e308a4944...7242706251
```
* [CHANGE] Cache: Switch Memcached backend to use `github.com/grafana/gomemcache` repository instead of `github.com/bradfitz/gomemcache`. #248
* [ENHANCEMENT] Add cache, gate and stringsutil packages. #239
* [ENHANCEMENT] Cache: add Redis support. #245
* [ENHANCEMENT] Cache: Add the ability to use a custom memory allocator for cache results. #249
* [BUGFIX] Memberlist: fix crash when methods from `memberlist.Delegate` interface are called on `*memberlist.KV` before the service is fully started. #244
```
**Checklist**
- [x] Reviewed the [`CONTRIBUTING.md`](../CONTRIBUTING.md) guide
(**required**)
- N/A Documentation added
- N/A Tests updated
- N/A `CHANGELOG.md` updated
- N/A Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
pull/8159/head
parent
d317e659c7
commit
6ea5a8e497
@ -0,0 +1,11 @@ |
||||
package slices |
||||
|
||||
func Contains[T comparable](haystack []T, needle T) bool { |
||||
for _, e := range haystack { |
||||
if e == needle { |
||||
return true |
||||
} |
||||
} |
||||
|
||||
return false |
||||
} |
@ -1,12 +0,0 @@ |
||||
package util |
||||
|
||||
// StringsContain returns true if the search value is within the list of input values.
|
||||
func StringsContain(values []string, search string) bool { |
||||
for _, v := range values { |
||||
if search == v { |
||||
return true |
||||
} |
||||
} |
||||
|
||||
return false |
||||
} |
@ -0,0 +1,59 @@ |
||||
package memcache |
||||
|
||||
var nopAllocator = &defaultAllocator{} |
||||
|
||||
func newOptions(opts ...Option) *Options { |
||||
o := &Options{ |
||||
Alloc: nopAllocator, |
||||
} |
||||
|
||||
for _, opt := range opts { |
||||
opt(o) |
||||
} |
||||
|
||||
return o |
||||
} |
||||
|
||||
// Options are used to modify the behavior of an individual Get or GetMulti
|
||||
// call made by the Client. They are constructed by applying Option callbacks
|
||||
// passed to a Client method to a default Options instance.
|
||||
type Options struct { |
||||
Alloc Allocator |
||||
} |
||||
|
||||
// Option is a callback used to modify the Options that a particular Client
|
||||
// method uses.
|
||||
type Option func(opts *Options) |
||||
|
||||
// WithAllocator creates a new Option that makes use of a specific memory Allocator
|
||||
// for result values (Item.Value) loaded from memcached.
|
||||
func WithAllocator(alloc Allocator) Option { |
||||
return func(opts *Options) { |
||||
opts.Alloc = alloc |
||||
} |
||||
} |
||||
|
||||
// Allocator allows memory for memcached result values (Item.Value) to be managed by
|
||||
// callers of the Client instead of by the Client itself. For example, this can be
|
||||
// used by callers to implement arena-style memory management. The default implementation
|
||||
// used, when not otherwise overridden, uses `make` and relies on GC for cleanup.
|
||||
type Allocator interface { |
||||
// Get returns a byte slice with at least sz capacity. Length of the slice is
|
||||
// not guaranteed and so must be asserted by callers (the Client).
|
||||
Get(sz int) *[]byte |
||||
// Put returns the byte slice to the underlying allocator. The Client will
|
||||
// only call this method during error handling when allocated values are not
|
||||
// returned to the caller as cache results.
|
||||
Put(b *[]byte) |
||||
} |
||||
|
||||
type defaultAllocator struct{} |
||||
|
||||
func (d defaultAllocator) Get(sz int) *[]byte { |
||||
b := make([]byte, sz) |
||||
return &b |
||||
} |
||||
|
||||
func (d defaultAllocator) Put(_ *[]byte) { |
||||
// no-op
|
||||
} |
Loading…
Reference in new issue