https://github.com/uppercod/cache
https://github.com/uppercod/cache
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/uppercod/cache
- Owner: UpperCod
- Created: 2020-08-18T06:00:57.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-22T03:28:43.000Z (over 5 years ago)
- Last Synced: 2024-04-25T02:42:34.075Z (about 2 years ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cache
This script creates an in-memory cache that allows:
1. The callback execution when regenerating the arguments.
2. Use references to return arguments.
## install
```
npm install cache
```
## Usage
Suppose that part was a high-cost process, such as template rendering or an asynchronous call.
```js
import createCache from "@uppercod/cache";
const cache = createCache();
function parse(code = "") {
return code.split(/ */);
}
/**
* the Cache function will only memorize the first execution, since there is no second parameter.
*/
const value1 = cache(parse);
/**
* The cache function will memorize the execution of the function based on the second parameter.
**/
const value2 = cache(parse, "my-code");
/**
* The cache function memorizes the execution of the function based on the arguments of the second parameter.
**/
const value3 = cache(parse, ["my-code"]);
```