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)
| 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). |
| 408 | func 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 | |
| 421 | func toMemcacheOptions(opts ...Option) []memcache.Option { |
| 422 | if len(opts) == 0 { |
no outgoing calls
no test coverage detected