RubyGems Navigation menu

safe_memoize 1.1.0

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.

Gemfile:
=

install:
=

Versions:

  1. 1.1.0 May 22, 2026 (52 KB)
  2. 1.0.0 May 22, 2026 (47 KB)
  3. 0.9.0 May 22, 2026 (34.5 KB)
  4. 0.8.0 May 22, 2026 (26 KB)
  5. 0.7.0 May 18, 2026 (22.5 KB)
Show all versions (15 total)

Development Dependencies (1):

simplecov ~> 0.22

Owners:

Pushed by:

GitHub

Authors:

  • Chuck Smith

SHA 256 checksum:

=

Total downloads 1,766

For this version 110

Version Released:

License:

MIT

Required Ruby Version: >= 3.3.0

Links: