Module: Tins::Memoize

Defined in:
lib/tins/memoize.rb

Overview

Note:

This module is deprecated in favor of the mize gem. Use ‘memoize method:` or `memoize function:` from the mize gem directly.

Provides memoization functionality for methods and functions with support for instance-level and class-level caching respectively.

Examples:

Basic method memoization

class Calculator
  def expensive_calculation(x, y)
    # Some expensive computation
    x * y
  end
  memoize_method :expensive_calculation
end

Function memoization (shared across instances)

class MathUtils
  def self.factorial(n)
    n <= 1 ? 1 : n * factorial(n - 1)
  end
  memoize_function :factorial
end

With freezing results

class DataProcessor
  def process_data(input)
    # Process data and return result
    input.dup
  end
  memoize_method :process_data, freeze: true
end

Defined Under Namespace

Modules: CacheMethods