A memoization macro for Elixir that caches function results using CAS on ETS for performance optimization.
Memoize is an Elixir library that provides a `defmemo` macro to easily add memoization to functions, caching the results of expensive calls to avoid redundant computations and speed up programs. It leverages Erlang's ETS with CAS operations for thread-safe, efficient caching and offers features like exclusive execution to prevent parallel calls and flexible cache invalidation.
Elixir developers working on applications with computationally expensive or frequently called functions where caching results can significantly improve performance, such as those implementing recursive algorithms, external API calls, or data transformation pipelines.
Developers choose Memoize for its simplicity—replacing `def` with `defmemo` after `use Memoize`—and its robust features like exclusive execution to ensure correctness, configurable cache strategies including expiration and eviction, and the ability to implement custom caching behaviors via the `Memoize.CacheStrategy` protocol.
A method caching macro for elixir using CAS on ETS.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Just replace `def` with `defmemo` after `use Memoize`, as shown in the Fibonacci example, making it effortless to add caching to existing functions.
Ensures memoized functions are never called in parallel, preventing duplicate work and race conditions, demonstrated with the `Calc.calc/0` example in the README.
Offers multiple strategies like Default and Eviction, with options for expiration and permanent caching, plus the ability to implement custom strategies via the `Memoize.CacheStrategy` behaviour.
Supports caching with partial arguments using `Memoize.Cache.get_or_run/2`, enabling advanced use cases beyond standard function memoization.
The `invalidate/{0-2}` functions have linear complexity, meaning they can degrade performance when invalidating many cached values, as explicitly warned in the README.
Advanced features like the Eviction strategy require careful tuning of thresholds and options, which can be error-prone and add overhead for simple caching needs.