BETAmodules.com is in beta — open to partnerships & joint ventures.Build with us

safe_memoize

v1.3.0RubyGems· Ruby

SafeMemoize is a production-ready, zero-dependency memoization library for Ruby. It uses Ruby's prepend mechanism to wrap methods with a thread-safe cache (Mutex + double-check locking) that correctly handles nil and false return values — fixing the silent bug in the common ||= pattern. Results are cached per unique argument combination, so parameterized methods only compute each variant once. Additional features include TTL expiration, LRU cache size limiting, conditional caching via if:/unless: predicates, lifecycle hooks for hit/eviction/expiration events, per-instance metrics (hit rate, miss rate, computation time), targeted cache invalidation, custom cache key generators, and introspection helpers. Method visibility (public, protected, private) is fully preserved.

The verdict
Maintained. Niche but maintained, actively maintained.
Live from the RubyGems registry · derived rules, not AI
How it scores
MaintenanceHealthy
PopularityNiche
SecurityClean
LicensePermissive
DepsZero deps
Maintenance
Last published this month.
Popularity
136 downloads / week
Security
No known advisories for this version (OSV).
License
MIT
Dependencies
No runtime dependencies
Recent releases
  • 1.3.0this month
  • 1.2.0this month
  • 1.1.0this month
  • 1.0.0this month
  • 0.9.0this month
  • 0.8.0this month
  • 0.7.0this month
  • 0.6.3this month
safe_memoize — SafeMemoize is a production-ready, zero-dependency memoization library for Ruby. It uses Ruby's prepend mechanism to wrap methods with a thread-safe cache (Mutex + double-check locking) that correctly handles nil and false return values — fixing the silent bug in the common ||= pattern. Results are cached per unique argument combination, so parameterized methods only compute each variant once. Additional features include TTL expiration, LRU cache size limiting, conditional caching via if:/unless: predicates, lifecycle hooks for hit/eviction/expiration events, per-instance metrics (hit rate, miss rate, computation time), targeted cache invalidation, custom cache key generators, and introspection helpers. Method visibility (public, protected, private) is fully preserved. (Ruby / RubyGems) · Modules