Skip to content

added a cacheFunction#3

Open
abdelrahman146 wants to merge 1 commit into0ss:mainfrom
abdelrahman146:feature/cacheFunction
Open

added a cacheFunction#3
abdelrahman146 wants to merge 1 commit into0ss:mainfrom
abdelrahman146:feature/cacheFunction

Conversation

@abdelrahman146
Copy link
Copy Markdown

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