https://github.com/keybase/node-lru
Simple JS LRU
https://github.com/keybase/node-lru
Last synced: 17 days ago
JSON representation
Simple JS LRU
- Host: GitHub
- URL: https://github.com/keybase/node-lru
- Owner: keybase
- License: other
- Archived: true
- Created: 2016-02-04T14:07:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T01:28:30.000Z (almost 2 years ago)
- Last Synced: 2025-04-02T19:37:58.827Z (about 1 month ago)
- Language: TypeScript
- Size: 605 KB
- Stars: 8
- Watchers: 5
- Forks: 6
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kb-node-lru
Simple JS LRU Cache, v3.0.0+ now written in TypeScript.
```
npm install kb-node-lru
``````javascript
import LRU from 'kb-node-lru'const cache1 = new LRU({maxAgeMs: 10000, maxStorage: 100})
const cache2 = new LRU({
maxAgeMs: 10000,
maxStorage: 100,
sizeFn: o => {
o.kilobytes_or_whatever()
},
})
const cache3 = new LRU({maxAgeMs: Infinity, maxStorage: Infinity})cache2.put('foo', someObject)
cache2.get('foo') // someObject
cache2.has('foo') // true
cache2.remove('foo') // removes it
cache2.toArray() // an array of objects with keys and access times
cache2.logMe() // returns big string for debugging
```### Contributing
- run `yarn modules` to install necessary dev modules
- run `yarn dev --watch` to watch typescript and compile while working
- run `yarn test` to make sure it passes all tests
- run `yarn memtest` to watch how much memory it uses with repeated large LRU creation/removals