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.
Required Ruby Version
>= 3.3.0
Authors
Chuck Smith
Versions
- 1.7.0 June 02, 2026 (83.5 KB)
- 1.6.0 June 02, 2026 (79 KB)
- 1.5.0 June 02, 2026 (75.5 KB)
- 1.4.0 June 02, 2026 (74 KB)
- 1.3.0 May 28, 2026 (70.5 KB)