Class: HatiConfig::Cache::CacheConfig

Inherits:
Object
  • Object
show all
Includes:
NumericConfigurable
Defined in:
lib/hati_config/cache.rb

Overview

CacheConfig class handles cache configuration and behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NumericConfigurable

included

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.

Parameters:

  • type (Symbol) —

    The adapter type (:memory, :redis)

  • options (Hash) —

    Options for the 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]
    options = args[1] || kwargs
    @adapter_type = type
    @adapter_options = 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
  @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