Skip to content

rixmann/memoize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memoize

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).

Installation

If available in Hex, the package can be installed as:

  1. Add memoize to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:memoize, "~> 0.1.0"}]
end
```
  1. Ensure memoize is started before your application:
```elixir
def application do
  [applications: [:memoize]]
end
```

Usage

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 executed

Documentation

If published on HexDocs, the docs can be found at https://hexdocs.pm/memoize

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages