Skip to content

ccapndave/elixir-memoized

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memoized

This package adds a defmemoized macro to Elixir. This is used to define a function that should be memoized - this means that after the first time it is called with a particular set of arguments, the result is stored and never recomputed.

The cache is local to the current process. Note that there are no expiration strategies or ways to remove entries from the cache; the cache will exist for the lifetime of the process. That makes this useful for shortlived processes like Phoenix Liveviews.

Warning!

  • Don't use memoization prematurely; there are often better solutions for optimization.
  • Used in the wrong place, memoization can decrease performance!
  • Careful not to memoize too much stuff or you could run out of memory.
  • This uses the process dictionary which might make you feel icky.

Installation

If available in Hex, the package can be installed by adding memoized to your list of dependencies in mix.exs:

def deps do
  [
    {:memoized, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/memoized.

About

A macro for memoizing pure functions in the process dictionary

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages