{"id":19926607,"url":"https://github.com/microlinkhq/async-memoize-one","last_synced_at":"2025-05-03T08:32:26.972Z","repository":{"id":40317954,"uuid":"317804075","full_name":"microlinkhq/async-memoize-one","owner":"microlinkhq","description":"memoize the last result, in async way.","archived":false,"fork":false,"pushed_at":"2024-05-09T14:45:00.000Z","size":38,"stargazers_count":29,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-19T10:08:49.264Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microlinkhq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-02T08:57:34.000Z","updated_at":"2024-09-07T14:05:44.000Z","dependencies_parsed_at":"2022-08-19T06:31:36.612Z","dependency_job_id":"6203d193-0522-46e5-891c-aecb6cccaf63","html_url":"https://github.com/microlinkhq/async-memoize-one","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"e37865e8a3048649a3426c59423b7e103e6b317e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fasync-memoize-one","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fasync-memoize-one/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fasync-memoize-one/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fasync-memoize-one/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microlinkhq","download_url":"https://codeload.github.com/microlinkhq/async-memoize-one/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224358040,"owners_count":17298038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T22:29:54.235Z","updated_at":"2024-11-12T22:29:55.020Z","avatar_url":"https://github.com/microlinkhq.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner.png#gh-light-mode-only\" alt=\"microlink logo\"\u003e\n  \u003cimg src=\"https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner-dark.png#gh-dark-mode-only\" alt=\"microlink logo\"\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n\u003c/div\u003e\n\n![Last version](https://img.shields.io/github/tag/microlinkhq/async-memoize-one.svg?style=flat-square)\n[![Coverage Status](https://img.shields.io/coveralls/microlinkhq/async-memoize-one.svg?style=flat-square)](https://coveralls.io/github/microlinkhq/async-memoize-one)\n[![NPM Status](https://img.shields.io/npm/dm/async-memoize-one.svg?style=flat-square)](https://www.npmjs.org/package/async-memoize-one)\n\n\u003e Memoize the last result, in async way.\n\n**async-memoize-one** simply remembers the last arguments, and if the function is next called with the same arguments then it returns the previous result.\n\nIt's used for [micro-caching](https://www.nginx.com/blog/benefits-of-microcaching-nginx/) scenarios, where you want to prevent perform an action previously done during a short period of time.\n\nNo need to worry about cache busting mechanisms such as maxAge, maxSize, exclusions and so on which can be prone to memory leaks.\n\n## Install\n\n```bash\n$ npm install async-memoize-one --save\n```\n\n## Usage\n\n```js\nconst get = require('util').promisify(require('simple-get'))\nconst memoizeOne = require('async-memoize-one')\n\nconst fetchData = memoizeOne(url =\u003e get(`https://api.microlink.io?url=${url}`))\n\n;(async () =\u003e {\n  // fecthing data for first time\n  console.time('fetch')\n  await fetchData('https://example.com/one')\n  console.timeEnd('fetch')\n\n  // served data from cache; no fetching!\n  console.time('fetch')\n  await fetchData('https://example.com/one')\n  console.timeEnd('fetch')\n\n  // previous execution parameters are different, so fetching again\n  console.time('fetch')\n  await fetchData('https://example.com/two')\n  console.timeEnd('fetch')\n\n  // previous execution parameters are different, so fetching again\n  console.time('fetch')\n  await fetchData('https://example.com/one')\n  console.timeEnd('fetch')\n})()\n```\n\n## API\n\n### memoizeOne(fn, [isEqual], [options])\n\n#### fn\n\n*Required*\u003cbr\u003e\nType: `function`\n\nPromise-returning or async function to be memoized.\n\n#### isEqual\n\nType: `function`\u003cbr\u003e\nDefault: [`fast-deep-equal`](https://github.com/epoberezkin/fast-deep-equal)\n\nThe compare function to determinate if both executions are the same.\n\nAn equality function should return true if the arguments are equal. If true is returned then the wrapped function will not be called.\n\n#### options\n\n##### cachePromiseRejection\n\nType: `boolean`\u003cbr\u003e\nDefault: `false`\n\nCache rejected promises.\n\n## License\n\n**async-memoize-one** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/async-memoize-one/blob/master/LICENSE.md) License.\u003cbr\u003e\nAuthored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/async-memoize-one/contributors).\n\n\u003e [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrolinkhq%2Fasync-memoize-one","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrolinkhq%2Fasync-memoize-one","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrolinkhq%2Fasync-memoize-one/lists"}