Skip to main content

Documentation 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 is a lightweight Angular library that makes it easy to cache expensive function calls and computed properties. By adding a simple decorator to your methods and getters, you can eliminate redundant calculations and dramatically improve your application’s performance.

Why memoization matters

In modern Angular applications, you often encounter scenarios where:
  • Complex calculations run repeatedly with the same inputs
  • API calls are made multiple times for identical data
  • Computed properties recalculate unnecessarily during change detection
  • Expensive transformations slow down your UI
Memoization solves these problems by caching function results. When a memoized function is called with arguments it has seen before, it returns the cached result instantly instead of recalculating.

Key features

Decorator-based API

Add @Ngememoize() to any method or getter for instant memoization

Configurable caching

Control cache lifetime with maxAge and size limits with maxSize

Custom key generation

Define your own cache key strategies for complex scenarios

Debug-friendly

Built-in logging with debugLabel to track cache hits and misses

Async support

Works seamlessly with Promises and async/await

Tree-shakable

Lightweight design with zero unnecessary overhead

Real-world use cases

E-commerce calculations

Cache price calculations that depend on discounts, shipping, and taxes:
@Ngememoize({
  maxAge: 5000,
  keyGenerator: (price, quantity) => `subtotal-${price}-${quantity}`
})
calculateSubtotal(price: number, quantity: number): number {
  return price * quantity;
}

Data transformations

Avoid re-filtering or re-sorting large datasets:
@Ngememoize()
get filteredUsers(): User[] {
  return this.users.filter(user => user.role === 'admin');
}

API response processing

Cache expensive transformations of API data:
@Ngememoize({ maxAge: 10000 })
async fetchData(id: string): Promise<string> {
  const response = await this.http.get(`/api/data/${id}`);
  return this.transformResponse(response);
}
Memoization is most effective when functions are pure (same inputs always produce the same outputs) and computationally expensive.

Performance benefits

By eliminating redundant calculations, Ngememoize can:
  • Reduce CPU usage - Skip expensive computations when results are cached
  • Speed up rendering - Return cached values instantly during change detection
  • Minimize API calls - Avoid duplicate network requests
  • Improve responsiveness - Make your UI feel snappier and more fluid

Getting started

Installation

Install Ngememoize in your Angular project

Quick start

Start memoizing functions in minutes

Advanced options

Learn about all available options

Angular compatibility

Ngememoize is designed for modern Angular applications:
  • Angular 19+ - Full support with peer dependency requirement
  • Standalone components - Works perfectly with the latest Angular patterns
  • Signals-friendly - Complements Angular’s reactive primitives
Ngememoize is tree-shakable and adds minimal overhead to your bundle size.

Build docs developers (and LLMs) love