cache_config.go 432 B

12345678910111213141516171819202122232425262728
  1. package lru_memory_cache
  2. type Config struct {
  3. capacity uint
  4. }
  5. type ConfigOption func(*Config)
  6. type ConfigOptions []ConfigOption
  7. func (s *ConfigOptions) Add(option ConfigOption) {
  8. *s = append(*s, option)
  9. }
  10. func NewConfig(opts ...ConfigOption) Config {
  11. c := &Config{}
  12. for _, opt := range opts {
  13. opt(c)
  14. }
  15. return *c
  16. }
  17. func WithCapacity(capacity uint) ConfigOption {
  18. return func(s *Config) {
  19. s.capacity = capacity
  20. }
  21. }