memoize v1.1.1 Memoize

Link to this section Summary

Link to this section Functions

Link to this macro defmemo(call, expr_or_opts \\ nil) (macro)

Define the memoized function.

Below code:

defmemo foo(0, y) do
  y
end

defmemo foo(x, y) when x == 1 do
  y * z
end

defmemo foo(x, y, z \\ 0) when x == 2 do
  y * z
end

is converted to:

def foo(t1, t2) do
  Memoize.Cache.get_or_run({__MODULE__, :foo, [t1, t2]}, fn -> __foo_memoize(t1, t2) end)
end

def foo(t1, t2, t3) do
  Memoize.Cache.get_or_run({__MODULE__, :foo, [t1, t2, t3]}, fn -> __foo_memoize(t1, t2, t3) end)
end

defmemo __foo_memoize(0, y) do
  y
end

defmemo __foo_memoize(x, y) when x == 1 do
  y * z
end

defmemo __foo_memoize(x, y, z \\ 0) when x == 2 do
  y * z
end
Link to this macro defmemo(call, opts, expr) (macro)
Link to this macro defmemop(call, expr_or_opts \\ nil) (macro)
Link to this macro defmemop(call, opts, expr) (macro)
Link to this function invalidate(module)
Link to this function invalidate(module, function)
Link to this function invalidate(module, function, arguments)
Link to this function memory_strategy()