Class: Lutaml::Hal::Cache::CacheConfiguration

Inherits:
Model::Serializable
  • Object
show all
Defined in:
lib/lutaml/hal/cache/cache_configuration.rb

Constant Summary collapse

DEFAULT_TTL =
3600
DEFAULT_MAX_SIZE =
1000
DEFAULT_ADAPTER_TYPE =
'memory'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_config(config) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 18

def self.from_config(config)
  return new if config.nil?

  case config
  when Hash
    from_hash(config)
  when Symbol, String
    from_simple_config(config)
  else
    raise ArgumentError, "Invalid cache configuration: #{config.inspect}"
  end
end

Instance Method Details

#effective_adapter_typeObject



46
47
48
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 46

def effective_adapter_type
  adapter_type || DEFAULT_ADAPTER_TYPE
end

#effective_max_sizeObject



42
43
44
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 42

def effective_max_size
  max_size || DEFAULT_MAX_SIZE
end

#effective_ttlObject



38
39
40
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 38

def effective_ttl
  ttl || DEFAULT_TTL
end

#to_cache_store_configObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 50

def to_cache_store_config
  base = {
    adapter: { type: effective_adapter_type.to_sym },
    default_ttl: effective_ttl,
    max_size: effective_max_size
  }
  options = adapter_config&.dig(:options) || adapter_config&.dig('options')
  base[:adapter_options] = options if options
  base
end

#validate!Object



31
32
33
34
35
36
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 31

def validate!
  validate_adapter_type!
  validate_ttl!
  validate_max_size!
  validate_adapter_config!
end