Ngememoize helps you improve performance by caching expensive function results. This guide covers the fundamentals of using theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/akbarsaputrait/ngememoize/llms.txt
Use this file to discover all available pages before exploring further.
@Ngememoize decorator.
Installation
First, install Ngememoize via npm:Importing the decorator
Import theNgememoize decorator from the package:
Memoizing methods
Call the method multiple times
When you call the method with the same arguments, Ngememoize returns the cached result:
Memoizing getters
You can also memoize getters to cache computed properties:Common patterns
Price calculations
Memoize expensive calculations that run frequently:Shipping calculations
Cache results that depend on multiple conditions:How caching works
Ngememoize generates cache keys by serializing your function arguments. When you call a memoized function:- Ngememoize generates a key from the arguments
- If the key exists in the cache, it returns the cached value
- If not, it executes the function and stores the result
- Future calls with identical arguments return the cached result
Arguments with
null or undefined values are filtered out before generating the cache key.When to use memoization
Memoization works best for:- Pure functions that always return the same output for the same input
- Expensive calculations or transformations
- Frequently called methods with repeated arguments
- Computed properties that don’t change often
Next steps
- Learn about advanced options like
maxAge,maxSize, and custom key generators - Discover how to memoize async functions
- Explore debugging techniques to monitor cache performance