cacheopt.go 480 B

123456789101112131415161718192021222324252627282930313233
  1. package internal
  2. import "time"
  3. const (
  4. defaultExpiry = time.Hour * 24 * 7
  5. defaultNotFoundExpiry = time.Minute
  6. )
  7. type (
  8. Options struct {
  9. Expiry time.Duration
  10. NotFoundExpiry time.Duration
  11. }
  12. Option func(o *Options)
  13. )
  14. func newOptions(opts ...Option) Options {
  15. var o Options
  16. for _, opt := range opts {
  17. opt(&o)
  18. }
  19. if o.Expiry <= 0 {
  20. o.Expiry = defaultExpiry
  21. }
  22. if o.NotFoundExpiry <= 0 {
  23. o.NotFoundExpiry = defaultNotFoundExpiry
  24. }
  25. return o
  26. }