Class: Lutaml::Hal::Cache::CacheConfiguration
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Hal::Cache::CacheConfiguration
- Defined in:
- lib/lutaml/hal/cache/cache_configuration.rb
Overview
Represents cache configuration with validation and defaults
Constant Summary collapse
- DEFAULT_TTL =
Default configuration values
3600- DEFAULT_MAX_SIZE =
1000- DEFAULT_ADAPTER_TYPE =
'memory'
Class Method Summary collapse
- .extract_adapter_type(adapter_info) ⇒ Object
-
.from_config(config) ⇒ Object
Create configuration from hash or symbol.
- .from_hash(config) ⇒ Object
- .from_simple_config(config) ⇒ Object
Instance Method Summary collapse
-
#basic_cache? ⇒ Boolean
Check if basic caching should be used.
-
#basic_cache_config ⇒ Object
Get basic cache configuration hash.
-
#effective_adapter_type ⇒ Object
Get the effective adapter type (with fallback to default).
-
#effective_max_size ⇒ Object
Get the effective max size (with fallback to default).
-
#effective_ttl ⇒ Object
Get the effective TTL (with fallback to default).
-
#http_aware? ⇒ Boolean
Check if HTTP-aware caching should be used.
-
#http_cache_config ⇒ Object
Get HTTP cache configuration hash.
-
#validate! ⇒ Object
Validate the configuration.
Class Method Details
.extract_adapter_type(adapter_info) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 121 def self.extract_adapter_type(adapter_info) case adapter_info when Hash type = adapter_info[:type] || adapter_info['type'] type&.to_s when Symbol, String adapter_info.to_s end end |
.from_config(config) ⇒ Object
Create configuration from hash or symbol
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 25 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 |
.from_hash(config) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 99 def self.from_hash(config) adapter_info = config[:adapter] || config['adapter'] || {} # Handle direct adapter_type specification adapter_type = config[:adapter_type] || config['adapter_type'] || extract_adapter_type(adapter_info) new( adapter_type: adapter_type, adapter_config: adapter_info.is_a?(Hash) ? adapter_info : nil, ttl: config[:ttl] || config['ttl'], max_size: config[:max_size] || config['max_size'], http_aware: config.key?(:http_aware) ? config[:http_aware] : config['http_aware'], respect_http_headers: config.key?(:respect_http_headers) ? config[:respect_http_headers] : config['respect_http_headers'], enable_conditional_requests: config.key?(:enable_conditional_requests) ? config[:enable_conditional_requests] : config['enable_conditional_requests'], ignore_query_params: config[:ignore_query_params] || config['ignore_query_params'] ) end |
.from_simple_config(config) ⇒ Object
117 118 119 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 117 def self.from_simple_config(config) new(adapter_type: config.to_s) end |
Instance Method Details
#basic_cache? ⇒ Boolean
Check if basic caching should be used
57 58 59 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 57 def basic_cache? !http_aware? end |
#basic_cache_config ⇒ Object
Get basic cache configuration hash
89 90 91 92 93 94 95 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 89 def basic_cache_config { adapter: adapter_config || { type: effective_adapter_type.to_sym }, default_ttl: effective_ttl, max_size: effective_max_size } end |
#effective_adapter_type ⇒ Object
Get the effective adapter type (with fallback to default)
72 73 74 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 72 def effective_adapter_type adapter_type || DEFAULT_ADAPTER_TYPE end |
#effective_max_size ⇒ Object
Get the effective max size (with fallback to default)
67 68 69 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 67 def effective_max_size max_size || DEFAULT_MAX_SIZE end |
#effective_ttl ⇒ Object
Get the effective TTL (with fallback to default)
62 63 64 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 62 def effective_ttl ttl || DEFAULT_TTL end |
#http_aware? ⇒ Boolean
Check if HTTP-aware caching should be used
HTTP-aware caching (conditional requests backed by a response cache) is opt-in: it only applies when explicitly enabled and the lutaml-store HTTP cache backend is available. By default the register uses the basic object cache, which stores realized models directly.
52 53 54 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 52 def http_aware? http_aware == true && http_cache_available? end |
#http_cache_config ⇒ Object
Get HTTP cache configuration hash
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 77 def http_cache_config { adapter_type: effective_adapter_type.to_sym, default_ttl: effective_ttl, max_entries: effective_max_size, respect_http_headers: respect_http_headers != false, enable_conditional_requests: enable_conditional_requests != false, ignore_query_params: parse_ignore_query_params }.merge(adapter_config || {}) end |
#validate! ⇒ Object
Validate the configuration
39 40 41 42 43 44 |
# File 'lib/lutaml/hal/cache/cache_configuration.rb', line 39 def validate! validate_adapter_type! validate_ttl! validate_max_size! validate_adapter_config! end |