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

Method incrDecr

cache/memcached_client.go:507–533  ·  view source on GitHub ↗
(ctx context.Context, key string, operation string, f func() (uint64, error))

Source from the content-addressed store, hash-verified

505}
506
507func (c *MemcachedClient) incrDecr(ctx context.Context, key string, operation string, f func() (uint64, error)) (uint64, error) {
508 var (
509 newValue uint64
510 err error
511 )
512 start := time.Now()
513 c.metrics.operations.WithLabelValues(operation).Inc()
514
515 select {
516 case <-ctx.Done():
517 err = ctx.Err()
518 default:
519 newValue, err = f()
520 }
521 if err != nil {
522 c.trackError(
523 operation, err,
524 "msg", "failed to incr/decr cache item",
525 "operation", operation,
526 "key", key,
527 )
528 } else {
529 c.metrics.duration.WithLabelValues(operation).Observe(time.Since(start).Seconds())
530 }
531
532 return newValue, err
533}
534
535func (c *MemcachedClient) Touch(ctx context.Context, key string, ttl time.Duration) error {
536 start := time.Now()

Callers 2

IncrementMethod · 0.95
DecrementMethod · 0.95

Calls 3

trackErrorMethod · 0.95
DoneMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected