Class: HatiConfig::Cache::CacheConfig
- Inherits:
-
Object
- Object
- HatiConfig::Cache::CacheConfig
- Includes:
- NumericConfigurable
- Defined in:
- lib/hati_config/cache.rb
Overview
CacheConfig class handles cache configuration and behavior.
Instance Attribute Summary collapse
-
#adapter(*args, **kwargs) ⇒ Object
Sets the cache adapter.
-
#adapter_options ⇒ Object
readonly
Returns the value of attribute adapter_options.
-
#adapter_type ⇒ Object
readonly
Returns the value of attribute adapter_type.
Instance Method Summary collapse
-
#initialize ⇒ CacheConfig
constructor
A new instance of CacheConfig.
- #refresh(&block) ⇒ Object
- #stale_while_revalidate(enabled = nil) ⇒ Object
Methods included from NumericConfigurable
Constructor Details
#initialize ⇒ CacheConfig
Returns a new instance of CacheConfig.
78 79 80 81 82 83 84 85 |
# File 'lib/hati_config/cache.rb', line 78 def initialize @adapter_type = :memory @adapter_options = {} @ttl = 300 @stale_while_revalidate = false @refresh_config = RefreshConfig.new @adapter = nil end |
Instance Attribute Details
#adapter(*args, **kwargs) ⇒ Object
Sets the cache adapter.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hati_config/cache.rb', line 91 def adapter(*args, **kwargs) if args.empty? && kwargs.empty? @adapter ||= initialize_adapter else type = args[0] = args[1] || kwargs @adapter_type = type @adapter_options = @adapter = nil self end end |
#adapter_options ⇒ Object (readonly)
Returns the value of attribute adapter_options.
60 61 62 |
# File 'lib/hati_config/cache.rb', line 60 def @adapter_options end |
#adapter_type ⇒ Object (readonly)
Returns the value of attribute adapter_type.
60 61 62 |
# File 'lib/hati_config/cache.rb', line 60 def adapter_type @adapter_type end |
Instance Method Details
#refresh(&block) ⇒ Object
64 65 66 67 |
# File 'lib/hati_config/cache.rb', line 64 def refresh(&block) @refresh_config.instance_eval(&block) if block_given? @refresh_config end |
#stale_while_revalidate(enabled = nil) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/hati_config/cache.rb', line 69 def stale_while_revalidate(enabled = nil) if enabled.nil? @stale_while_revalidate else @stale_while_revalidate = enabled self end end |