Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yields/lru-cache

LRU Cache
https://github.com/yields/lru-cache

Last synced: 2 months ago
JSON representation

LRU Cache

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'); // => 5ms

by 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