Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: isaacs/node-lru-cache
...
head fork: isaacs/node-lru-cache
compare: special-keys-2
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 19, 2013
@isaacs simpler second-pass at this 0679e37
Showing with 16 additions and 14 deletions.
  1. +8 −6 lib/lru-cache.js
  2. +8 −8 test/basic.js
View
14 lib/lru-cache.js
@@ -155,7 +155,8 @@ function LRUCache (options) {
return lruList
}
- this.set = function (key, value) {
+ this.set = function (k, value) {
+ var key = 'lru_' + k
if (hOP(cache, key)) {
// dispose of the old one before overwriting
if (dispose) dispose(key, cache[key].value)
@@ -167,7 +168,7 @@ function LRUCache (options) {
var len = lengthCalculator(value)
var age = maxAge ? Date.now() : 0
- var hit = new Entry(key, value, mru++, len, age)
+ var hit = new Entry(k, value, mru++, len, age)
// oversized objects fall out of cache automatically.
if (hit.length > max) {
@@ -183,7 +184,8 @@ function LRUCache (options) {
return true
}
- this.has = function (key) {
+ this.has = function (k) {
+ key = 'lru_' + k
if (!hOP(cache, key)) return false
var hit = cache[key]
if (maxAge && (Date.now() - hit.now > maxAge)) {
@@ -201,7 +203,7 @@ function LRUCache (options) {
}
function get (key, doUse) {
- var hit = cache[key]
+ var hit = cache['lru_' + key]
if (hit) {
if (maxAge && (Date.now() - hit.now > maxAge)) {
del(hit)
@@ -221,7 +223,7 @@ function LRUCache (options) {
}
this.del = function (key) {
- del(cache[key])
+ del(cache['lru_' + key])
}
function trim () {
@@ -239,7 +241,7 @@ function LRUCache (options) {
if (dispose) dispose(hit.key, hit.value)
length -= hit.length
itemCount --
- delete cache[ hit.key ]
+ delete cache['lru_' + hit.key]
shiftLU(hit)
}
}
View
16 test/basic.js
@@ -101,18 +101,18 @@ test("dump", function (t) {
t.equal(Object.keys(d).length, 0, "nothing in dump for empty cache")
cache.set("a", "A")
var d = cache.dump() // { a: { key: "a", value: "A", lu: 0 } }
- t.ok(d.a)
- t.equal(d.a.key, "a")
- t.equal(d.a.value, "A")
- t.equal(d.a.lu, 0)
+ t.ok(d.lru_a)
+ t.equal(d.lru_a.key, "a")
+ t.equal(d.lru_a.value, "A")
+ t.equal(d.lru_a.lu, 0)
cache.set("b", "B")
cache.get("b")
d = cache.dump()
- t.ok(d.b)
- t.equal(d.b.key, "b")
- t.equal(d.b.value, "B")
- t.equal(d.b.lu, 2)
+ t.ok(d.lru_b)
+ t.equal(d.lru_b.key, "b")
+ t.equal(d.lru_b.value, "B")
+ t.equal(d.lru_b.lu, 2)
t.end()
})

No commit comments for this range

Something went wrong with that request. Please try again.