Class: Cachext::Configuration
- Inherits:
-
Object
- Object
- Cachext::Configuration
- Defined in:
- lib/cachext/configuration.rb
Constant Summary collapse
- MissingConfiguration =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#breaker_timeout ⇒ Object
raise all errors all the time? (for tests).
-
#cache ⇒ Object
raise all errors all the time? (for tests).
-
#debug ⇒ Object
raise all errors all the time? (for tests).
-
#default_errors ⇒ Object
raise all errors all the time? (for tests).
-
#default_expires_in ⇒ Object
raise all errors all the time? (for tests).
-
#error_logger ⇒ Object
raise all errors all the time? (for tests).
-
#failure_threshold ⇒ Object
raise all errors all the time? (for tests).
-
#heartbeat_expires ⇒ Object
raise all errors all the time? (for tests).
-
#max_lock_wait ⇒ Object
raise all errors all the time? (for tests).
-
#not_found_errors ⇒ Object
raise all errors all the time? (for tests).
-
#raise_errors ⇒ Object
raise all errors all the time? (for tests).
-
#redis ⇒ Object
raise all errors all the time? (for tests).
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #lock_manager ⇒ Object
- #lock_redis ⇒ Object
- #log_errors? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
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_timeout ⇒ Object
raise all errors all the time? (for tests)
7 8 9 |
# File 'lib/cachext/configuration.rb', line 7 def breaker_timeout @breaker_timeout end |
#cache ⇒ Object
raise all errors all the time? (for tests)
7 8 9 |
# File 'lib/cachext/configuration.rb', line 7 def cache @cache end |
#debug ⇒ Object
raise all errors all the time? (for tests)
7 8 9 |
# File 'lib/cachext/configuration.rb', line 7 def debug @debug end |
#default_errors ⇒ Object
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_in ⇒ Object
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_logger ⇒ Object
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_threshold ⇒ Object
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_expires ⇒ Object
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_wait ⇒ Object
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_errors ⇒ Object
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_errors ⇒ Object
raise all errors all the time? (for tests)
7 8 9 |
# File 'lib/cachext/configuration.rb', line 7 def raise_errors @raise_errors end |
#redis ⇒ Object
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
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_manager ⇒ Object
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_redis ⇒ Object
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
65 66 67 |
# File 'lib/cachext/configuration.rb', line 65 def log_errors? error_logger.present? end |