{"id":17399252,"url":"https://github.com/feross/async-lru","last_synced_at":"2025-09-13T00:32:46.316Z","repository":{"id":57185669,"uuid":"82249200","full_name":"feross/async-lru","owner":"feross","description":"A simple async LRU cache supporting O(1) set, get and eviction of old keys","archived":false,"fork":false,"pushed_at":"2020-05-25T04:27:17.000Z","size":20,"stargazers_count":46,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-02T08:44:27.719Z","etag":null,"topics":["async","browser","javascript","lru","lru-cache","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-17T02:39:12.000Z","updated_at":"2024-09-25T09:11:06.000Z","dependencies_parsed_at":"2022-09-06T04:02:10.645Z","dependency_job_id":null,"html_url":"https://github.com/feross/async-lru","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fasync-lru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fasync-lru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fasync-lru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fasync-lru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/async-lru/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232804099,"owners_count":18578979,"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":["async","browser","javascript","lru","lru-cache","nodejs"],"created_at":"2024-10-16T15:14:09.521Z","updated_at":"2025-01-07T00:30:17.396Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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/async-lru/master.svg\n[travis-url]: https://travis-ci.org/feross/async-lru\n[npm-image]: https://img.shields.io/npm/v/async-lru.svg\n[npm-url]: https://npmjs.org/package/async-lru\n[downloads-image]: https://img.shields.io/npm/dm/async-lru.svg\n[downloads-url]: https://npmjs.org/package/async-lru\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### A simple async LRU cache supporting O(1) set, get and eviction of old keys\n\nAlso works in the browser with [browserify](http://browserify.org/)!\n\n## install\n\n```\nnpm install async-lru\n```\n\n## usage\n\n```js\nconst AsyncLRU = require('async-lru')\nconst fs = require('fs')\n\nconst lru = new AsyncLRU({\n  max: 2,\n  load: (key, cb) =\u003e {\n    fs.readFile(key, cb)\n  }\n})\n\nlru.get('file.txt', (err, value) =\u003e { // not in cache, calls load()\n  lru.get('file.txt', (err, value) =\u003e { // cached, will NOT call load()\n    // ...\n  })\n})\n```\n\n### Differences from [`lru`](https://www.npmjs.com/package/lru)\n\nSince values are fetched asynchronously, the `get` method takes a callback, rather\nthan returning the value synchronously.\n\nWhile there is a `set(key, value)` method to manually seed the cache, typically\nyou'll just call `get` and let the `load` function fetch the key for you.\n\nKeys must uniquely identify a single object, and must contain all the information\nrequired to fetch an object.\n\n## API\n\n### `lru = AsyncLRU(opts)`\n\nCreate a new AsyncLRU cache. You must pass an options map with a `load` option:\n\n```js\n{\n  load: function (key, callback) {\n    callback(null, 'value') // get the data from an asyncronous store\n  }\n}\n```\n\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**Returns**: the newly created AsyncLRU cache\n\n### `lru.length`\n\nThe number of keys currently in the cache.\n\n### `lru.keys`\n\nArray of all the keys currently in the cache.\n\n### `lru.set(key, value)`\n\nSet the value of the key and mark the key as most recently used.\n\n**Returns**: `value`\n\n### `lru.get(key, [loadArgs], callback)`\n\nQuery the value of the key and mark the key as most recently used.\n\nIf the key is in the cache, then calls `callback(null, cached)` on `nextTick`.\nOtherwise, calls `load(key, callback)` where `load` is the function that was\nsupplied in the options object. If it doesn't return an error, then cache the\nresult. Multiple `get` calls with the same `key` will only ever have a single\n`load` call at the same time.\n\nOptionally, specify `loadArgs` if you want a custom array of arguments to be passed\ninto `load` instead of `key`, like `load.apply(null, loadArgs.concat(callback))`.\n\n### `lru.peek(key)`\n\nQuery the value of the key without marking the key as most recently used.\n\n**Returns**: value of key if found; `undefined` otherwise.\n\n### `lru.remove(key)`\n\nRemove the value from the cache.\n\n**Returns**: value of key if found; `undefined` otherwise.\n\n### `lru.clear()`\n\nClear the cache. This method does **NOT** emit the `evict` event.\n\n### `lru.on(event, callback)`\n\nRespond to events. Currently only the `evict` event is implemented. When a key is\nevicted, the callback is executed with an associative array containing the evicted\nkey: `{key: key, value: value}`.\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%2Fasync-lru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fasync-lru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fasync-lru/lists"}