Class: SafeMemoize::Configuration

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

Overview

Global configuration for SafeMemoize.

Obtain an instance via configure or configuration.

Examples:

SafeMemoize.configure do |c|
  c.default_ttl = 300
  c.default_max_size = 100
  c.on_hook_error = ->(err, type, key) { Bugsnag.notify(err) }
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Configuration.



46
47
48
49
50
51
52
53
54
# File 'lib/safe_memoize/configuration.rb', line 46

def initialize
  @default_ttl = nil
  @default_max_size = nil
  @on_deprecation = nil
  @on_hook_error = nil
  @active_support_notifications = false
  @statsd_client = nil
  @opentelemetry_tracer = nil
end

Instance Attribute Details

#active_support_notificationsBoolean

Returns When +true+, SafeMemoize emits +ActiveSupport::Notifications+ events for cache hits, misses, stores, evictions, and expirations. Requires +activesupport+ to be loaded; has zero overhead when it is not.

Returns:

  • (Boolean)

    When +true+, SafeMemoize emits +ActiveSupport::Notifications+ events for cache hits, misses, stores, evictions, and expirations. Requires +activesupport+ to be loaded; has zero overhead when it is not.



35
36
37
# File 'lib/safe_memoize/configuration.rb', line 35

def active_support_notifications
  @active_support_notifications
end

#default_max_sizeInteger?

Returns Default LRU size cap applied to every SafeMemoize::ClassMethods#memoize call that does not specify its own +max_size:+. +nil+ means unlimited.

Returns:



21
22
23
# File 'lib/safe_memoize/configuration.rb', line 21

def default_max_size
  @default_max_size
end

#default_ttlNumeric?

Returns Default TTL (seconds) applied to every SafeMemoize::ClassMethods#memoize call that does not specify its own +ttl:+. +nil+ means no expiry.

Returns:



17
18
19
# File 'lib/safe_memoize/configuration.rb', line 17

def default_ttl
  @default_ttl
end

#on_deprecationProc?

Returns Custom handler for deprecation warnings. Receives a single +String+ message. When +nil+, warnings are written to +$stderr+.

Returns:

  • (Proc, nil)

    Custom handler for deprecation warnings. Receives a single +String+ message. When +nil+, warnings are written to +$stderr+.



25
26
27
# File 'lib/safe_memoize/configuration.rb', line 25

def on_deprecation
  @on_deprecation
end

#on_hook_errorProc?

Returns Custom handler for errors raised inside lifecycle hooks. Receives +(Exception, Symbol hook_type, cache_key)+. When +nil+, a warning is written to +$stderr+ and the error is swallowed.

Returns:

  • (Proc, nil)

    Custom handler for errors raised inside lifecycle hooks. Receives +(Exception, Symbol hook_type, cache_key)+. When +nil+, a warning is written to +$stderr+ and the error is swallowed.



30
31
32
# File 'lib/safe_memoize/configuration.rb', line 30

def on_hook_error
  @on_hook_error
end

#opentelemetry_tracerObject?

Returns An OpenTelemetry tracer (responds to +#in_span+). When set, Adapters::OpenTelemetry wraps each cache-miss computation in a span.

Returns:

  • (Object, nil)

    An OpenTelemetry tracer (responds to +#in_span+). When set, Adapters::OpenTelemetry wraps each cache-miss computation in a span.



43
44
45
# File 'lib/safe_memoize/configuration.rb', line 43

def opentelemetry_tracer
  @opentelemetry_tracer
end

#statsd_clientObject?

Returns Any StatsD-compatible client (responds to +#increment+). When set, Adapters::StatsD routes lifecycle events to this client.

Returns:

  • (Object, nil)

    Any StatsD-compatible client (responds to +#increment+). When set, Adapters::StatsD routes lifecycle events to this client.



39
40
41
# File 'lib/safe_memoize/configuration.rb', line 39

def statsd_client
  @statsd_client
end