lru

WebJar for lru

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

lru
Последняя версия

Последняя версия

3.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

lru
WebJar for lru
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/chriso/lru

Скачать lru

Имя Файла Размер
lru-3.1.0.pom
lru-3.1.0.jar 7 KB
lru-3.1.0-sources.jar 22 bytes
lru-3.1.0-javadoc.jar 22 bytes
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/lru/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>lru</artifactId>
    <version>3.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/lru/
implementation 'org.webjars.npm:lru:3.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/lru/
implementation ("org.webjars.npm:lru:3.1.0")
'org.webjars.npm:lru:jar:3.1.0'
<dependency org="org.webjars.npm" name="lru" rev="3.1.0">
  <artifact name="lru" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='lru', version='3.1.0')
)
libraryDependencies += "org.webjars.npm" % "lru" % "3.1.0"
[org.webjars.npm/lru "3.1.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : inherits jar [2.0.1,3)

Модули Проекта

Данный проект не имеет модулей.

lru

A simple LRU cache supporting O(1) set, get and eviction of old keys

Installation

$ npm install lru

Example

var LRU = require('lru');

var cache = new LRU(2),
    evicted

cache.on('evict',function(data) { evicted = data });

cache.set('foo', 'bar');
cache.get('foo'); //=> bar

cache.set('foo2', 'bar2');
cache.get('foo2'); //=> bar2

cache.set('foo3', 'bar3'); // => evicted = { key: 'foo', value: 'bar' }
cache.get('foo3');         // => 'bar3'
cache.remove('foo2')       // => 'bar2'
cache.remove('foo4')       // => undefined
cache.length               // => 1
cache.keys                 // => ['foo3']

cache.clear()              // => it will NOT emit the 'evict' event
cache.length               // => 0
cache.keys                 // => []

API

LRU( length )

Create a new LRU cache that stores length elements before evicting the least recently used. Optionally you can pass an options map with additional options:

{
  max: maxElementsToStore,
  maxAge: maxAgeInMilliseconds
}

If you pass maxAge items will be evicted if they are older than maxAge when you access them.

Returns: the newly created LRU cache

Properties

.length

The number of keys currently in the cache.

.keys

Array of all the keys currently in the cache.

Methods

.set( key, value )

Set the value of the key and mark the key as most recently used.

Returns: value

.get( key )

Query the value of the key and mark the key as most recently used.

Returns: value of key if found; undefined otherwise.

.peek( key )

Query the value of the key without marking the key as most recently used.

Returns: value of key if found; undefined otherwise.

.remove( key )

Remove the value from the cache.

Returns: value of key if found; undefined otherwise.

.clear()

Clear the cache. This method does NOT emit the evict event.

.on( event, callback )

Respond to events. Currently only the evict event is implemented. When a key is evicted, the callback is executed with an associative array containing the evicted key: {key: key, value: value}.

Credits

A big thanks to Dusty Leary who finished the library.

License

MIT

Версии библиотеки

Версия
3.1.0