{"id":17399267,"url":"https://github.com/feross/memo-async-lru","last_synced_at":"2025-09-13T01:32:22.120Z","repository":{"id":57294416,"uuid":"82279041","full_name":"feross/memo-async-lru","owner":"feross","description":"Memoize Node.js style callback-last functions, using an in-memory LRU store","archived":false,"fork":false,"pushed_at":"2020-05-25T04:28:03.000Z","size":12,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-03T02:53:08.464Z","etag":null,"topics":["browser","browserify","callback","javascript","lru","lru-cache","memoize","nodejs"],"latest_commit_sha":null,"homepage":"","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/feross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-17T09:14:09.000Z","updated_at":"2024-09-25T09:11:07.000Z","dependencies_parsed_at":"2022-08-29T07:51:06.494Z","dependency_job_id":null,"html_url":"https://github.com/feross/memo-async-lru","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmemo-async-lru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmemo-async-lru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmemo-async-lru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmemo-async-lru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/memo-async-lru/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232806956,"owners_count":18579340,"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":["browser","browserify","callback","javascript","lru","lru-cache","memoize","nodejs"],"created_at":"2024-10-16T15:14:30.315Z","updated_at":"2025-01-07T01:18:06.247Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memo-async-lru [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/memo-async-lru/master.svg\n[travis-url]: https://travis-ci.org/feross/memo-async-lru\n[npm-image]: https://img.shields.io/npm/v/memo-async-lru.svg\n[npm-url]: https://npmjs.org/package/memo-async-lru\n[downloads-image]: https://img.shields.io/npm/dm/memo-async-lru.svg\n[downloads-url]: https://npmjs.org/package/memo-async-lru\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Memoize Node.js style callback-last functions, using an in-memory LRU store\n\nAlso works in the browser with [browserify](http://browserify.org/)!\n\n## install\n\n```\nnpm install memo-async-lru\n```\n\n## usage\n\n```js\nconst memo = require('memo-async-lru')\n\nfunction fn (arg, cb) {\n  t.equal(arg, 'foo')\n  cb(null, 'bar')\n}\n\nconst memoFn = memo(fn)\n\nmemoFn('foo', (err, result) =\u003e {\n  console.log(result) // prints 'bar'\n\n  memoFn('foo', (err, result) =\u003e {\n    console.log(result) // prints 'bar', cached, does not call fn()\n  })\n})\n```\n\n## API\n\n### `memo(fn, [opts])`\n\nMemoize the given function `fn`, using\n[`async-lru`](https://www.npmjs.com/package/async-lru), a simple async LRU cache supporting\nO(1) set, get and eviction of old keys.\n\nThe function must be a Node.js style function, where the last argument is a callback.\n\n  function(key: Object, [...], fetch: function(err: Error, value: Object))\n\nSo, if you were to do:\n\n```js\nconst readFile = memo(fs.readFile)\nreadFile('file.txt', fn)\nreadFile('file.txt', fn) // \u003c-- this uses the cache\n```\n\nThe file would only be read from disk once, it's value cached, and returned\nanytime the first argument is 'file.txt'.\n\nRepeated calls to the function with the same first argument will return a\ncached value, rather than re-fetch the data.\n\nOptionally, an `opts` parameter can be specified with the following properties:\nOptional options:\n\n```js\n{\n  max: maxElementsToStore,\n  maxAge: maxAgeInMilliseconds\n}\n```\n\nIf you pass `max`, items will be evicted if the cache is storing more than `max` items.\nIf you pass `maxAge`, items will be evicted if they are older than `maxAge` when you access them.\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fmemo-async-lru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fmemo-async-lru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fmemo-async-lru/lists"}