Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a cacheFunction #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abdelrahman146
Copy link

The cacheFunction method takes a function and its parameters and adds it value in the cacheMap and return its value. if the passed cacheKey and the parameters are already cached. then it will not run the function again instead it will jus return the cached value. if the parameters values have changed then it will create another cache in the cache map.

Example:

    const sum = (...nums: number[]) => nums.reduce((total, curr) => total + curr, 0);
    let result = cache.cacheFunction('sum', sum, [1, 2, 3]);
    expect(result).toBe(6);
    result = cache.cacheFunction('sum', sum, [3, 4, 5]);
    expect(result).toBe(12);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant