Class: RailsNamedCache::Configuration
- Inherits:
-
Object
- Object
- RailsNamedCache::Configuration
- Defined in:
- lib/rails_named_cache/configuration.rb
Overview
Turns the raw config.named_cache_stores value into cache store instances.
Values may be:
- an
ActiveSupport::Cache::Storeinstance (used as-is) - anything
ActiveSupport::Cache.lookup_storeunderstands, e.g.:memory_storeor[:redis_cache_store, { url: ENV["REDIS_URL"] }]
Configuration only resolves and validates; it never stores anything. The Registry owns state.
Instance Attribute Summary collapse
-
#stores ⇒ Hash
readonly
The raw configured value.
Instance Method Summary collapse
-
#initialize(stores = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#resolved_stores ⇒ Hash{Symbol=>ActiveSupport::Cache::Store}
Name => store instance.
Constructor Details
#initialize(stores = {}) ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_named_cache/configuration.rb', line 27 def initialize(stores = {}) stores ||= {} unless stores.is_a?(Hash) raise ConfigurationError, "config.named_cache_stores must be a Hash of name => cache store, got #{stores.class}" end @stores = stores end |
Instance Attribute Details
#stores ⇒ Hash (readonly)
Returns the raw configured value.
23 24 25 |
# File 'lib/rails_named_cache/configuration.rb', line 23 def stores @stores end |
Instance Method Details
#resolved_stores ⇒ Hash{Symbol=>ActiveSupport::Cache::Store}
Returns name => store instance.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails_named_cache/configuration.rb', line 40 def resolved_stores stores.each_with_object({}) do |(name, value), resolved| key = RailsNamedCache.normalize_name(name) # "memory" and :memory are the same store; silently keeping the last one # would hide a typo in config. if resolved.key?(key) raise ConfigurationError, "Duplicate named cache store #{key.inspect} in config.named_cache_stores" end resolved[key] = resolve(key, value) end end |