Module: SafeMemoize
- Includes:
- InstanceMethods
- Defined in:
- lib/safe_memoize.rb,
lib/safe_memoize/rails.rb,
lib/safe_memoize/version.rb,
lib/safe_memoize/lru_methods.rb,
lib/safe_memoize/class_methods.rb,
lib/safe_memoize/configuration.rb,
lib/safe_memoize/hooks_methods.rb,
lib/safe_memoize/public_methods.rb,
lib/safe_memoize/adapters/statsd.rb,
lib/safe_memoize/release_tooling.rb,
lib/safe_memoize/instance_methods.rb,
lib/safe_memoize/rails/middleware.rb,
lib/safe_memoize/custom_key_methods.rb,
lib/safe_memoize/inspection_methods.rb,
lib/safe_memoize/cache_store_methods.rb,
lib/safe_memoize/cache_record_methods.rb,
lib/safe_memoize/rails/request_scoped.rb,
lib/safe_memoize/cache_metrics_methods.rb,
lib/safe_memoize/adapters/opentelemetry.rb,
lib/safe_memoize/public_metrics_methods.rb,
lib/safe_memoize/public_custom_key_methods.rb
Overview
Thread-safe memoization for Ruby that correctly handles +nil+ and +false+ values.
Prepend this module into any class, then call ClassMethods#memoize to wrap instance methods with a per-instance cache backed by a +Mutex+.
Defined Under Namespace
Modules: Adapters, CacheMetricsMethods, CacheRecordMethods, CacheStoreMethods, ClassMethods, CustomKeyMethods, HooksMethods, InspectionMethods, InstanceMethods, LruMethods, PublicCustomKeyMethods, PublicMethods, PublicMetricsMethods, Rails, ReleaseTooling Classes: Configuration, Error
Constant Summary collapse
- VERSION =
The current gem version string.
"1.0.0"
Constants included from HooksMethods
HooksMethods::NOTIFICATION_EVENT_NAMES
Class Method Summary collapse
-
.configuration ⇒ Configuration
Returns the global Configuration instance, creating it on first access.
-
.configure {|config| ... } ⇒ void
Yields the global Configuration object for mutation.
-
.deprecate(subject, message:, horizon:) ⇒ void
Emits a structured deprecation warning through the configured handler.
- .prepended(base) ⇒ Object private
-
.reset_configuration! ⇒ Configuration
Resets the global configuration to all defaults.
Methods included from PublicCustomKeyMethods
#clear_custom_keys, #memoize_with_custom_key
Methods included from PublicMetricsMethods
#cache_hit_rate, #cache_metrics_reset, #cache_miss_rate, #cache_stats, #cache_stats_for
Methods included from PublicMethods
#clear_memo_hooks, #dump_memo, #load_memo, #memo_age, #memo_count, #memo_inspect, #memo_keys, #memo_preload, #memo_refresh, #memo_stale?, #memo_touch, #memo_ttl_remaining, #memo_values, #memoized?, #on_memo_evict, #on_memo_expire, #on_memo_hit, #on_memo_miss, #on_memo_store, #reset_all_memos, #reset_memo, #warm_memo
Class Method Details
.configuration ⇒ Configuration
Returns the global Configuration instance, creating it on first access.
76 77 78 |
# File 'lib/safe_memoize.rb', line 76 def self.configuration @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ void
This method returns an undefined value.
Yields the global Configuration object for mutation.
69 70 71 |
# File 'lib/safe_memoize.rb', line 69 def self.configure yield configuration end |
.deprecate(subject, message:, horizon:) ⇒ void
This method returns an undefined value.
Emits a structured deprecation warning through the configured handler.
95 96 97 98 99 |
# File 'lib/safe_memoize.rb', line 95 def self.deprecate(subject, message:, horizon:) text = "[SafeMemoize] #{subject} is deprecated and will be removed in #{horizon}. #{}" handler = configuration.on_deprecation handler ? handler.call(text) : warn(text) end |
.prepended(base) ⇒ Object
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.
55 56 57 |
# File 'lib/safe_memoize.rb', line 55 def self.prepended(base) base.extend(ClassMethods) end |
.reset_configuration! ⇒ Configuration
Resets the global configuration to all defaults.
Useful in test suites to prevent configuration leaking between examples.
85 86 87 |
# File 'lib/safe_memoize.rb', line 85 def self.reset_configuration! @configuration = Configuration.new end |