summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md')
-rw-r--r--deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md55
1 files changed, 30 insertions, 25 deletions
diff --git a/deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md b/deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md
index c06814e041..1bc7b03f3e 100644
--- a/deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md
+++ b/deps/npm/node_modules/request/node_modules/aws4/node_modules/lru-cache/README.md
@@ -2,12 +2,14 @@
A cache object that deletes the least-recently-used items.
+[![Build Status](https://travis-ci.org/isaacs/node-lru-cache.svg?branch=master)](https://travis-ci.org/isaacs/node-lru-cache) [![Coverage Status](https://coveralls.io/repos/isaacs/node-lru-cache/badge.svg?service=github)](https://coveralls.io/github/isaacs/node-lru-cache)
+
## Usage:
```javascript
var LRU = require("lru-cache")
, options = { max: 500
- , length: function (n) { return n * 2 }
+ , length: function (n, key) { return n * 2 + key.length }
, dispose: function (key, n) { n.close() }
, maxAge: 1000 * 60 * 60 }
, cache = LRU(options)
@@ -16,6 +18,12 @@ var LRU = require("lru-cache")
cache.set("key", "value")
cache.get("key") // "value"
+// non-string keys ARE fully supported
+var someObject = {}
+cache.set(someObject, 'a value')
+cache.set('[object Object]', 'a different value')
+assert.equal(cache.get(someObject), 'a value')
+
cache.reset() // empty the cache
```
@@ -24,24 +32,6 @@ If you put more stuff in it, then items will fall out.
If you try to put an oversized thing in it, then it'll fall out right
away.
-## Keys should always be Strings or Numbers
-
-Note: this module will print warnings to `console.error` if you use a
-key that is not a String or Number. Because items are stored in an
-object, which coerces keys to a string, it won't go well for you if
-you try to use a key that is not a unique string, it'll cause surprise
-collisions. For example:
-
-```JavaScript
-// Bad Example! Dont' do this!
-var cache = LRU()
-var a = {}
-var b = {}
-cache.set(a, 'this is a')
-cache.set(b, 'this is b')
-console.log(cache.get(a)) // prints: 'this is b'
-```
-
## Options
* `max` The maximum size of the cache, checked by applying the length
@@ -53,9 +43,10 @@ console.log(cache.get(a)) // prints: 'this is b'
drop it and return undefined instead of giving it to you.
* `length` Function that is used to calculate the length of stored
items. If you're storing strings or buffers, then you probably want
- to do something like `function(n){return n.length}`. The default is
- `function(n){return 1}`, which is fine if you want to store `max`
- like-sized things.
+ to do something like `function(n, key){return n.length}`. The default is
+ `function(){return 1}`, which is fine if you want to store `max`
+ like-sized things. They item is passed as the first argument, and
+ the key is passed as the second argumnet.
* `dispose` Function that is called on items when they are dropped
from the cache. This can be handy if you want to close file
descriptors or do other cleanup tasks when items are no longer
@@ -76,8 +67,12 @@ console.log(cache.get(a)) // prints: 'this is b'
* `get(key) => value`
Both of these will update the "recently used"-ness of the key.
- They do what you think. `max` is optional and overrides the
- cache `max` option if provided.
+ They do what you think. `maxAge` is optional and overrides the
+ cache `maxAge` option if provided.
+
+ If the key is not found, `get()` will return `undefined`.
+
+ The key and val can be any value.
* `peek(key)`
@@ -107,6 +102,12 @@ console.log(cache.get(a)) // prints: 'this is b'
in the cache, in order of recent-ness. (Ie, more recently used
items are iterated over first.)
+* `rforEach(function(value,key,cache), [thisp])`
+
+ The same as `cache.forEach(...)` but items are iterated over in
+ reverse order. (ie, less recently used items are iterated over
+ first.)
+
* `keys()`
Return an array of the keys in the cache.
@@ -115,7 +116,7 @@ console.log(cache.get(a)) // prints: 'this is b'
Return an array of the values in the cache.
-* `length()`
+* `length`
Return total length of objects in cache taking into account
`length` options function.
@@ -135,3 +136,7 @@ console.log(cache.get(a)) // prints: 'this is b'
Loads another cache entries array, obtained with `sourceCache.dump()`,
into the cache. The destination cache is reset before loading new entries
+
+* `prune()`
+
+ Manually iterates over the entire cache proactively pruning old entries