Skip to content

feat: add @memoize decorator with expiration and handler options#63

Merged
tabkram merged 1 commit intomainfrom
feature/memoize
Mar 10, 2025
Merged

feat: add @memoize decorator with expiration and handler options#63
tabkram merged 1 commit intomainfrom
feature/memoize

Conversation

@tabkram
Copy link
Copy Markdown
Owner

@tabkram tabkram commented Mar 9, 2025

Summary:

This PR introduces the @memoize decorator for method memoization, caching results to avoid redundant calculations.

Key Changes:

  • @memoize decorator: Caches method results based on arguments.
  • expirationMs: Configurable cache expiration time.
  • memoizationHandler: Optional callback after checking the cache.

Usage:

Decorate methods with @memoize to cache results for repeated calls with the same inputs. This improves performance by reusing stored results.

Example:

class Calculator {
  @memoize()
  fibonacci(n: number): number {
    if (n <= 1) return n;
    return this.fibonacci(n - 1) + this.fibonacci(n - 2);
  }
}

@tabkram tabkram self-assigned this Mar 9, 2025
@tabkram tabkram added the deploy deploy a canary version to NPM label Mar 9, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2025

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
95.38% (-0.62% 🔻)
351/368
🟢 Branches
87.75% (-0.63% 🔻)
222/253
🟢 Functions
92.08% (-2.43% 🔻)
93/101
🟢 Lines
96.84% (+0.09% 🔼)
337/348
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / crypto.ts
100% 100% 100% 100%
🟢
... / memoizeDecorator.ts
100% 50% 100% 100%
🟢
... / memoize.ts
84% 80% 25% 95.45%
🟢
... / executionMemoization.model.ts
100% 100% 100% 100%

Test suite run success

84 tests passing in 11 suites.

Report generated by 🧪jest coverage report action from 662c1fa

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2025

🚫 Unpublished versions: ∅
Created Version: 3.2.0-canary.63.66812c4
📦 Published on NPM: View on NPM

⚠️ Note: This version is temporary and will be unpublished on the next PR update or merge.

@github-actions
Copy link
Copy Markdown
Contributor

🚫 Unpublished versions: 3.2.0-canary.63.66812c4
Created Version: 3.2.0-canary.63.6fa9874
📦 Published on NPM: View on NPM

⚠️ Note: This version is temporary and will be unpublished on the next PR update or merge.

@github-actions
Copy link
Copy Markdown
Contributor

🚫 Unpublished versions: 3.2.0-canary.63.6fa9874
Created Version: 3.2.0-canary.63.9df5c66
📦 Published on NPM: View on NPM

⚠️ Note: This version is temporary and will be unpublished on the next PR update or merge.

Added `@memoize` decorator for caching result of calls with identical input:
- Prevents redundant calls using `executeMemoize`.
- Supports configurable expiration and memoization tracking.
- Update `functionMetadata` model and add `methodSignature`

The expiration is capped at 1000ms for efficiency and to avoid unnecessary memory usage.
@github-actions
Copy link
Copy Markdown
Contributor

🚫 Unpublished versions: 3.2.0-canary.63.9df5c66
Created Version: 3.2.0-canary.63.add4a1d
📦 Published on NPM: View on NPM

⚠️ Note: This version is temporary and will be unpublished on the next PR update or merge.

@tabkram tabkram merged commit 1c30ccc into main Mar 10, 2025
8 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🚫 Unpublished versions: 3.2.0-canary.63.add4a1d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy deploy a canary version to NPM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant