Class: Cachext::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cachext/configuration.rb

Constant Summary collapse

MissingConfiguration =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cachext/configuration.rb', line 39

def initialize
  self.raise_errors = false
  self.default_errors = [
    Faraday::Error::ConnectionFailed,
    Faraday::Error::TimeoutError,
  ]
  self.not_found_errors = [
    Faraday::Error::ResourceNotFound,
  ]
  self.default_expires_in = 60
  self.max_lock_wait = 5
  self.debug = ENV['CACHEXT_DEBUG'] == "true"
  self.heartbeat_expires = 2
  self.failure_threshold = 3
  self.breaker_timeout = 60
  @debug_mutex = Mutex.new
end

Instance Attribute Details

#breaker_timeoutObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def breaker_timeout
  @breaker_timeout
end

#cacheObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def cache
  @cache
end

#debugObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def debug
  @debug
end

#default_errorsObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def default_errors
  @default_errors
end

#default_expires_inObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def default_expires_in
  @default_expires_in
end

#error_loggerObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def error_logger
  @error_logger
end

#failure_thresholdObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def failure_threshold
  @failure_threshold
end

#heartbeat_expiresObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def heartbeat_expires
  @heartbeat_expires
end

#max_lock_waitObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def max_lock_wait
  @max_lock_wait
end

#not_found_errorsObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def not_found_errors
  @not_found_errors
end

#raise_errorsObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def raise_errors
  @raise_errors
end

#redisObject

raise all errors all the time? (for tests)



7
8
9
# File 'lib/cachext/configuration.rb', line 7

def redis
  @redis
end

Class Method Details

.setup {|config| ... } ⇒ Object

Yields:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cachext/configuration.rb', line 22

def self.setup
  config = new
  yield config

  if config.cache.nil?
    raise MissingConfiguration, "Must configure the config.cache. Try config.cache = Rails.cache"
  end

  if config.redis.nil?
    raise MissingConfiguration, "Must configure the config.redis. Try config.redis = Redis.current"
  end

  config.lock_manager

  config
end

Instance Method Details

#lock_managerObject



57
58
59
# File 'lib/cachext/configuration.rb', line 57

def lock_manager
  @lock_manager ||= Redlock::Client.new [lock_redis], retry_count: 1
end

#lock_redisObject



61
62
63
# File 'lib/cachext/configuration.rb', line 61

def lock_redis
  @lock_redis ||= Redis::Namespace.new :cachext, redis: redis
end

#log_errors?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/cachext/configuration.rb', line 65

def log_errors?
  error_logger.present?
end