MCPcopy
hub / github.com/grafana/dskit / CompareAndSwap

Method CompareAndSwap

cache/memcached_client.go:558–576  ·  view source on GitHub ↗
(ctx context.Context, key string, value []byte, ttl time.Duration)

Source from the content-addressed store, hash-verified

556}
557
558func (c *MemcachedClient) CompareAndSwap(ctx context.Context, key string, value []byte, ttl time.Duration) error {
559 return c.storeOperation(ctx, key, value, ttl, opCompareAndSwap, func(ctx context.Context, key string, value []byte, ttl time.Duration) error {
560 select {
561 case <-ctx.Done():
562 return ctx.Err()
563 default:
564 ttlSeconds, ok := toSeconds(ttl)
565 if !ok {
566 return fmt.Errorf("%w: for compare-and-swap operation on %s %s", ErrInvalidTTL, key, ttl)
567 }
568
569 return c.client.CompareAndSwap(&memcache.Item{
570 Key: key,
571 Value: value,
572 Expiration: ttlSeconds,
573 })
574 }
575 })
576}
577
578func (c *MemcachedClient) FlushAll(ctx context.Context) error {
579 var err error

Callers

nothing calls this directly

Calls 6

storeOperationMethod · 0.95
toSecondsFunction · 0.85
ErrorfMethod · 0.80
DoneMethod · 0.65
CompareAndSwapMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected