Module: Plutonium::Lib::SmartCache

Extended by:
ActiveSupport::Concern
Defined in:
lib/plutonium/lib/smart_cache.rb

Overview

The SmartCache module provides flexible caching mechanisms for classes and objects, allowing for both inline caching and method-level memoization.

This module is designed to optimize performance by caching results when class caching is enabled (typically in production), while ensuring fresh results when caching is disabled (typically in development).

This implementation is thread-safe.

Examples:

Including SmartCache in a class

class MyClass
  include Plutonium::Lib::SmartCache

  def my_method(arg)
    cache_unless_reloading("my_method_#{arg}") { expensive_operation(arg) }
  end

  def another_method(arg)
    # Method implementation
  end
  memoize_unless_reloading :another_method
end