Class: AtomicCache::DefaultConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/atomic_cache/default_config.rb

Constant Summary collapse

CONFIG_MUTEX =
Mutex.new
FLOAT_TIME_FORMATTER =
Proc.new { |time| time.to_f }
TIMESTAMP_SEC_FORMATTER =
Proc.new { |time| time.to_i }
TIMESTAMP_MS_FORMATTER =
Proc.new { |time| (time.to_f * 1000).to_i }
ISO8601_FORMATTER =
Proc.new { |time| time.iso8601 }
DEFAULT_TIME_FORMATTER =
FLOAT_TIME_FORMATTER
DEFAULT_SEPARATOR =
':'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultConfig

Returns a new instance of DefaultConfig.



30
31
32
# File 'lib/atomic_cache/default_config.rb', line 30

def initialize
  reset
end

Instance Attribute Details

#cache_storageObject

storage adapter instance for cached values



20
21
22
# File 'lib/atomic_cache/default_config.rb', line 20

def cache_storage
  @cache_storage
end

#default_optionsObject

optional

config



23
24
25
# File 'lib/atomic_cache/default_config.rb', line 23

def default_options
  @default_options
end

#key_storageObject

required

config



19
20
21
# File 'lib/atomic_cache/default_config.rb', line 19

def key_storage
  @key_storage
end

#loggerObject

Returns the value of attribute logger.



25
26
27
# File 'lib/atomic_cache/default_config.rb', line 25

def logger
  @logger
end

#metricsObject

Returns the value of attribute metrics.



26
27
28
# File 'lib/atomic_cache/default_config.rb', line 26

def metrics
  @metrics
end

#namespaceObject

Returns the value of attribute namespace.



24
25
26
# File 'lib/atomic_cache/default_config.rb', line 24

def namespace
  @namespace
end

#separatorObject

Returns the value of attribute separator.



28
29
30
# File 'lib/atomic_cache/default_config.rb', line 28

def separator
  @separator
end

#timestamp_formatterObject

Returns the value of attribute timestamp_formatter.



27
28
29
# File 'lib/atomic_cache/default_config.rb', line 27

def timestamp_formatter
  @timestamp_formatter
end

Class Method Details

.configure {|config| ... } ⇒ Object

Quickly configure config singleton instance

Yields:

  • mutate config

Yield Parameters:



53
54
55
56
57
58
59
60
# File 'lib/atomic_cache/default_config.rb', line 53

def self.configure
  if block_given?
    manager = self.instance
    CONFIG_MUTEX.synchronize do
      yield(manager)
    end
  end
end

.resetObject

Change all configured values back to default



46
47
48
# File 'lib/atomic_cache/default_config.rb', line 46

def self.reset
  self.instance.reset
end

Instance Method Details

#resetObject

Change all configured values back to default



35
36
37
38
39
40
41
42
43
# File 'lib/atomic_cache/default_config.rb', line 35

def reset
  @cache_client = nil
  @default_options = {}
  @namespace = nil
  @logger = nil
  @metrics = nil
  @timestamp_formatter = DEFAULT_TIME_FORMATTER
  @separator = DEFAULT_SEPARATOR
end