Memoize is a library which caches a function calls parameters and the resulting value to retrieve them from the cache on succeeding calls with the same function parameters.
This happens opaque to the programmer (just use defmemoize keyword insted of def).
If available in Hex, the package can be installed as:
- Add
memoizeto your list of dependencies inmix.exs:
```elixir
def deps do
[{:memoize, "~> 0.1.0"}]
end
```
- Ensure
memoizeis started before your application:
```elixir
def application do
[applications: [:memoize]]
end
```
Define memoized functions by using the defmemoize macro.
Very simple usage example:
defmodule TestModule do
import Memoize
defmemoize testfun(a, b), do: a + b
end
2 = testfun(1, 1) # regular execution of function body
2 = testfun(1, 1) # result value retrieved from cache, function body not executedIf published on HexDocs, the docs can be found at https://hexdocs.pm/memoize