{"id":20936224,"url":"https://github.com/adzerk/node-lru-native","last_synced_at":"2025-08-04T06:34:56.357Z","repository":{"id":969521,"uuid":"12348597","full_name":"adzerk/node-lru-native","owner":"adzerk","description":"High-performance LRU cache for node.js","archived":false,"fork":false,"pushed_at":"2023-04-15T14:06:19.000Z","size":329,"stargazers_count":95,"open_issues_count":13,"forks_count":25,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-04-02T08:11:10.496Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adzerk.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,"governance":null}},"created_at":"2013-08-24T19:22:41.000Z","updated_at":"2025-03-26T21:14:29.000Z","dependencies_parsed_at":"2023-07-06T01:52:37.424Z","dependency_job_id":null,"html_url":"https://github.com/adzerk/node-lru-native","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fnode-lru-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fnode-lru-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fnode-lru-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fnode-lru-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adzerk","download_url":"https://codeload.github.com/adzerk/node-lru-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254030899,"owners_count":22002670,"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-18T22:18:25.057Z","updated_at":"2025-05-13T21:30:59.533Z","avatar_url":"https://github.com/adzerk.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"lru-native2\n===========\n[![Build Status](https://travis-ci.org/d3m3vilurr/node-lru-native.svg?branch=master)](https://travis-ci.org/d3m3vilurr/node-lru-native)\n\nThis is an implementation of a simple in-memory cache for node.js, supporting LRU (least-recently-used) eviction\nand TTL expirations.\n\nIt was developed as an alternative to the (excellent) [node-lru-cache](https://github.com/isaacs/node-lru-cache)\nlibrary for use with hashes with a very large number of items. V8 normally does a good job of optimizing the\nin-memory representation of objects, but it isn't optimized for an object that holds a huge amount of data.\nWhen you add a very large number of properties (particularly with non-integer keys) to an object, performance\nbegins to suffer.\n\nRather than rely on V8 to figure out what we're trying to do, `node-lru-native` is a light wrapper around\n`std::unordered_map` from C++11. A `std::list` is used to track accesses so we can evict the least-recently-used\nitem when necessary.\n\nBased on the [node-hashtable](https://github.com/isaacbwagner/node-hashtable) library by Issac Wagner.\n\n# Usage\n\nInstall via npm:\n\n```\n$ npm install lru-native2\n```\n\nThen:\n\n```javascript\nvar LRUCache = require('lru-native2');\nvar cache = new LRUCache({ maxElements: 1000 });\ncache.set('some-key', 42);\nvar value = cache.get('some-key');\n```\n\nIf you'd like to tinker, you can build the extension using [node-gyp](https://github.com/TooTallNate/node-gyp):\n\n```\n$ npm install -g node-gyp\n$ node-gyp configure\n$ node-gyp build\n```\n\n# Configuration\n\nTo configure the cache, you can pass a hash to the `LRUCache` constructor with the following options:\n\n```\nvar cache = new LRUCache({\n\n  // The maximum number of items to add to the cache before evicting the least-recently-used item.\n  // Default: 0, meaning there is no maximum.\n  maxElements: 10000,\n\n  // The maximum age (in milliseconds) of an item.\n  // The item will be removed if get() is called and the item is too old.\n  // Default: 0, meaning items will never expire.\n  maxAge: 60000,\n\n  // The initial number of items for which space should be allocated.\n  // The cache will resize dynamically if necessary.\n  size: 1000,\n\n  // The maximum load factor for buckets in the unordered_map.\n  // Typically you won't need to change this.\n  maxLoadFactor: 2.0\n\n});\n```\n\n# API\n\n## set(key, value)\n\nAdds the specified item to the cache with the specified key.\n\n## get(key)\n\nReturns the item with the specified key, or `undefined` if no item exists with that key.\n\n## remove(key)\n\nRemoves the item with the specified key if it exists.\n\n## clear()\n\nRemoves all items from the cache.\n\n## size()\n\nReturns the number of items in the cache.\n\n## stats()\n\nReturns a hash containing internal information about the cache.\n\n## setMaxElements(maxElements)\n\nSet the maximum number of items\n\n## setMaxAge(maxAge)\n\nSet the maximum age (in milliseconds) of an item\n\n\n# Changelog\n\n- 1.0.0 -- Update the timestamp when get a value(like common LRU cache). Added SetMaxAge(), SetMaxElements()\n- *forked*\n- 0.4.0 -- Added support for newer versions of Node via NAN\n- 0.3.0 -- Changed memory allocation strategy, fixed issue where remove() would do a seek through the LRU list, code cleanup\n- 0.2.0 -- Fixed issue where maxAge-based removal would result in a seek through the LRU list\n- 0.1.0 -- Initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadzerk%2Fnode-lru-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadzerk%2Fnode-lru-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadzerk%2Fnode-lru-native/lists"}