ttl-mem-cache
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -5,3 +5,4 @@ 'use strict'; | ||
const Cache = require('../'); | ||
const swarm = require('discovery-swarm'); | ||
const Swarm = require('discovery-swarm'); | ||
const split = require('split2'); | ||
@@ -12,2 +13,14 @@ const CHANNEL_NAME = 'test-swarm'; | ||
const options = { | ||
udp: false, | ||
dht: false, | ||
maxConnections: 2, | ||
}; | ||
const cacheA = new Cache(); | ||
const cacheB = new Cache(); | ||
const cacheC = new Cache(); | ||
const cacheD = new Cache(); | ||
const toJson = new stream.Transform({ | ||
@@ -17,6 +30,6 @@ writableObjectMode: true, | ||
transform(chunk, enc, next) { | ||
const c = new Buffer.from(JSON.stringify(chunk)); | ||
// const data = JSON.stringify(chunk); | ||
// this.push(data + '\n\n'); | ||
const c = Buffer.from(JSON.stringify(chunk)); | ||
const b = Buffer.from('\n\n'); | ||
this.push(c); | ||
this.push(b); | ||
next(); | ||
@@ -30,10 +43,10 @@ } | ||
transform(chunk, enc, next) { | ||
this.push(JSON.parse(chunk.toString())); | ||
/* | ||
chunk.toString().split('\n\n').filter(entry => entry).forEach((entry) => { | ||
console.log('foo', entry) | ||
chunk.toString().split('\n\n').sort().filter((item, index, arr) => { | ||
return item && (!index || item != arr[index - 1]); | ||
}).forEach((entry, x) => { | ||
const obj = JSON.parse(entry); | ||
console.log(x, obj); | ||
this.push(obj); | ||
}); | ||
*/ | ||
next(); | ||
@@ -43,14 +56,8 @@ } | ||
const cacheA = new Cache(); | ||
const cacheB = new Cache(); | ||
const cacheC = new Cache(); | ||
const a = new Swarm(Object.assign({ | ||
id: Buffer.from(cacheA.id) | ||
}, options)); | ||
const a = swarm({ | ||
udp: false, | ||
dht: false, | ||
}); | ||
a.on('peer', (peer) => { | ||
console.log('A got peer', peer.port); | ||
console.log('A got peer', peer); | ||
}); | ||
@@ -60,2 +67,4 @@ | ||
cacheA.pipe(toJson).pipe(connection); | ||
console.log('A connection', info); | ||
// connection.pipe(fromJson).pipe(cacheA).pipe(toJson).pipe(connection); | ||
}); | ||
@@ -66,4 +75,5 @@ | ||
cacheA.on('set', (info) => { | ||
console.log('set', info); | ||
console.log('A set', info); | ||
}); | ||
@@ -76,6 +86,5 @@ setTimeout(() => { | ||
const b = swarm({ | ||
udp: false, | ||
dht: false, | ||
}); | ||
const b = new Swarm(Object.assign({ | ||
id: Buffer.from(cacheB.id) | ||
}, options)); | ||
@@ -88,2 +97,4 @@ b.on('peer', (peer) => { | ||
connection.pipe(fromJson).pipe(cacheB); | ||
console.log('B connection', info); | ||
// connection.pipe(fromJson).pipe(cacheB).pipe(toJson).pipe(connection); | ||
}); | ||
@@ -94,8 +105,13 @@ | ||
const c = swarm({ | ||
udp: false, | ||
dht: false, | ||
cacheB.on('set', (info) => { | ||
console.log('B set', info); | ||
}); | ||
const c = new Swarm(Object.assign({ | ||
id: Buffer.from(cacheC.id) | ||
}, options)); | ||
c.on('peer', (peer) => { | ||
@@ -107,2 +123,4 @@ console.log('C got peer', peer.port); | ||
connection.pipe(fromJson).pipe(cacheC); | ||
console.log('C connection', info); | ||
// connection.pipe(fromJson).pipe(cacheC).pipe(toJson).pipe(connection); | ||
}); | ||
@@ -113,6 +131,35 @@ | ||
cacheC.on('set', (info) => { | ||
console.log('C set', info); | ||
}); | ||
const d = new Swarm(Object.assign({ | ||
id: Buffer.from(cacheD.id) | ||
}, options)); | ||
d.on('peer', (peer) => { | ||
console.log('D got peer', peer.port); | ||
}); | ||
d.on('connection', (connection, info) => { | ||
connection.pipe(fromJson).pipe(cacheD); | ||
console.log('D connection', info); | ||
// connection.pipe(fromJson).pipe(cacheC).pipe(toJson).pipe(connection); | ||
}); | ||
d.listen(0); | ||
d.join(CHANNEL_NAME); | ||
cacheD.on('set', (info) => { | ||
console.log('D set', info); | ||
}); | ||
setTimeout(() => { | ||
console.log('B', cacheB.get('foo')); | ||
console.log('C', cacheC.get('foo')); | ||
console.log('D', cacheD.get('foo')); | ||
}, 3000); |
@@ -20,2 +20,3 @@ 'use strict'; | ||
value: maxAge, | ||
enumerable: true, | ||
}); | ||
@@ -25,2 +26,3 @@ | ||
value: stale, | ||
enumerable: true, | ||
}); | ||
@@ -30,2 +32,3 @@ | ||
value: changefeed, | ||
enumerable: true, | ||
}); | ||
@@ -39,2 +42,3 @@ | ||
value: id || crypto.randomBytes(3 * 4).toString('base64'), | ||
enumerable: true, | ||
}); | ||
@@ -41,0 +45,0 @@ |
{ | ||
"name": "ttl-mem-cache", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A in memory time to live cache with streaming support.", | ||
@@ -5,0 +5,0 @@ "main": "lib/cache.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79628
1277