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

Function toSeconds

cache/memcached_client.go:408–419  ·  view source on GitHub ↗

toSeconds converts a time.Duration to seconds as an int32 and returns a boolean indicating if the value is valid to be used as a TTL. Durations might not be valid to be used for a TTL if they are non-zero but less than a second long (Memcached uses seconds for TTL units but "0" to mean infinite TTL)

(d time.Duration)

Source from the content-addressed store, hash-verified

406// uses seconds for TTL units but "0" to mean infinite TTL) or if they are longer than
407// 30 days (Memcached treats TTLs more than 30 days as UNIX timestamps).
408func toSeconds(d time.Duration) (int32, bool) {
409 if d > maxTTL {
410 return 0, false
411 }
412
413 secs := int32(d.Seconds())
414 if d != 0 && secs <= 0 {
415 return 0, false
416 }
417
418 return secs, true
419}
420
421func toMemcacheOptions(opts ...Option) []memcache.Option {
422 if len(opts) == 0 {

Callers 3

setSingleItemMethod · 0.85
AddMethod · 0.85
CompareAndSwapMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected