Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yields/lru-cache
LRU Cache
https://github.com/yields/lru-cache
Last synced: 2 months ago
JSON representation
LRU Cache
- Host: GitHub
- URL: https://github.com/yields/lru-cache
- Owner: yields
- Created: 2013-10-17T12:47:26.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-10-26T01:11:06.000Z (about 11 years ago)
- Last Synced: 2024-10-19T21:46:53.452Z (2 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# lru-cache
LRU Cache
## Installation
Install with [component(1)](http://component.io):
$ component install yields/lru-cache
## API
### Cache(opts)
Initialize `Cache` with `opts`
- `.max` max items.
#### #set
Set `key`, `val`.
`key` may be an object.an optional `ttl` may be given, if omitted the global `ttl` is used.
var c = cache();
c.set('a', 'b', '5ms');#### #get
Get `key`'s value, and promote it.
#### #has
Check if `key` exists.
#### #remove
Remove `key`
#### #max
Set `max` vals and remove items if necessary.
#### #ttl
Set `ttl` for all values, you can override this at a value level.
var c = cache({ ttl: '2ms' });
c.ttl('5ms');
c.set('a', 'b', '1ms');
c.set('d', 'c'); // => 5msby default `ttl` is `0`, which means no values will expire.
#### #toJSON
Get a cloned cache with `{ key: val }` structure.
#### #promote
Manually promote `key`.
## License
MIT