Socket
Socket
Sign inDemoInstall

lru

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.2 to 1.0.0

19

example/usage.js

@@ -1,2 +0,2 @@

var LRU = require('../').LRU
var LRU = require('../')

@@ -9,11 +9,14 @@ var cache = new LRU(2);

cache.set('foo', 'bar');
cache.get('foo'); //=> bar
cache.set('foo', 'bar'); // => 'bar'
cache.get('foo'); // => 'bar'
cache.set('foo2', 'bar2');
cache.get('foo2'); //=> bar2
cache.set('foo2', 'bar2'); // => 'bar2'
cache.get('foo2'); // => 'bar2'
cache.set('foo3', 'bar3');
cache.get('foo3'); //=> bar3, evicted = { key: 'foo', value: 'bar' }
cache.set('foo3', 'bar3'); // => 'bar3'
cache.get('foo3'); // => 'bar3'
console.log(evicted)
console.log(cache.remove('foo2')) // => { key: 'foo2', value: 'bar2' }
console.log(cache.remove('foo4')) // => undefined
console.log(cache.length) // => 1
console.log(evicted) // => evicted = { key: 'foo', value: 'bar' }
var events = require('events');
var util = require('util');
var LRU = exports.LRU = function (max) {
var LRU = module.exports = function (max) {
events.EventEmitter.call(this);

@@ -6,0 +6,0 @@ this.cache = {}

{
"name": "lru",
"description": "A simple O(1) LRU cache",
"version": "0.2.2",
"version": "1.0.0",
"author": "Chris O'Hara <cohara87@gmail.com>",
"main": "index",
"bugs": {
"mail": "cohara87@gmail.com"
},
"homepage": {
"url": "http://github.com/chriso/lru"
},
"homepage": "http://github.com/chriso/lru",
"repository": {

@@ -17,10 +12,9 @@ "type": "git",

},
"bugs": {
"url": "http://github.com/chriso/lru/issues"
},
"engines": {
"node": ">= 0.4.0"
},
"licenses": [
{
"type": "MIT"
}
],
"license": "MIT",
"devDependencies": {

@@ -27,0 +21,0 @@ "vows": "^0.8.1"

@@ -14,3 +14,3 @@ # lru

```javascript
var LRU = require('lru').LRU;
var LRU = require('lru');

@@ -28,4 +28,7 @@ var cache = new LRU(2),

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

@@ -35,3 +38,3 @@

#### `require('lru').LRU( length )`
#### `LRU( length )`
Create a new LRU cache that stores `length` elements before evicting the least recently used.

@@ -42,2 +45,6 @@

#### Properties
##### `.length`
The number of keys currently in the cache.
#### Methods

@@ -58,2 +65,7 @@

##### `.remove( key )`
Remove the key/value pair from the cache.
**Returns**: an associative array containing `{key: <key>, value: <value>}`
##### `.on( event, callback )`

@@ -60,0 +72,0 @@ 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}`.

var assert = require('assert');
var vows = require('vows');
var LRU = require('../').LRU;
var LRU = require('../');

@@ -5,0 +5,0 @@ function keys(obj) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc