(ctx context.Context, key string, operation string, f func() (uint64, error))
| 505 | } |
| 506 | |
| 507 | func (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 | |
| 535 | func (c *MemcachedClient) Touch(ctx context.Context, key string, ttl time.Duration) error { |
| 536 | start := time.Now() |
no test coverage detected