lru-cache-for-clusters-as-promised
Advanced tools
Comparing version 1.7.1 to 1.7.3
@@ -0,1 +1,14 @@ | ||
1.7.1 / 2021-03-25 | ||
================== | ||
* Added `static getInstance(options)` to asynchronously retun an `LRUCacheForClustersAsPromised` once the underlyig `LRUCache` is guaranteed to exist. | ||
* Added `static getAllCaches()` to return all underlying `LRUCache` instances keyed by namespace. *Use only when `cluster.isMaster === true`.* | ||
* Added `getCache()` to return underlying `LRUCache` instance. *Use only when `cluster.isMaster === true`.* | ||
* Add test coverage via github actions | ||
* Bug fixes for namespaces | ||
* Bug fixes for prune cron jobs | ||
* Refactoring for maintainability | ||
* Updated tests | ||
* Update dependencies | ||
1.7.0 / 2021-03-25 | ||
@@ -2,0 +15,0 @@ ================== |
{ | ||
"name": "lru-cache-for-clusters-as-promised", | ||
"version": "1.7.1", | ||
"version": "1.7.3", | ||
"types": "index.d.ts", | ||
"description": "LRU Cache that is safe for clusters", | ||
"description": "LRU Cache that is safe for clusters, based on `lru-cache`. Save memory by only caching items on the master thread via a pomisfied interface.", | ||
"main": "./lru-cache-for-clusters-as-promised.js", | ||
@@ -25,9 +25,12 @@ "scripts": { | ||
"keywords": [ | ||
"LRU", | ||
"lru", | ||
"mru", | ||
"cache", | ||
"lru-cache", | ||
"lru cache", | ||
"cluster", | ||
"promise", | ||
"master", | ||
"worker" | ||
"worker", | ||
"memory" | ||
], | ||
@@ -38,3 +41,3 @@ "author": "Justin Silver", | ||
"cron": "1.8.2", | ||
"debug": "4.3.1", | ||
"debug": "4.3.2", | ||
"lru-cache": "6.0.0", | ||
@@ -44,10 +47,10 @@ "uuid": "8.3.2" | ||
"devDependencies": { | ||
"async": "^3.2.0", | ||
"depcheck": "1.4.0", | ||
"eslint": "7.23.0", | ||
"eslint-plugin-mocha": "8.1.0", | ||
"async": "^3.2.1", | ||
"depcheck": "1.4.2", | ||
"eslint": "7.32.0", | ||
"eslint-plugin-mocha": "9.0.0", | ||
"express": "4.17.1", | ||
"flatted": "^3.1.1", | ||
"flatted": "^3.2.2", | ||
"istanbul-cobertura-badger": "1.3.1", | ||
"mocha": "8.3.2", | ||
"mocha": "9.0.3", | ||
"nyc": "15.1.0", | ||
@@ -57,3 +60,3 @@ "should": "13.2.3", | ||
"spec-xunit-file": "0.0.1-3", | ||
"supertest": "6.1.3" | ||
"supertest": "6.1.5" | ||
}, | ||
@@ -60,0 +63,0 @@ "pre-commit": [ |
@@ -6,4 +6,2 @@ # lru-cache-for-clusters-as-promised | ||
[![Code Climate](https://codeclimate.com/github/doublesharp/lru-cache-for-clusters-as-promised/badges/gpa.svg)](https://codeclimate.com/github/doublesharp/lru-cache-for-clusters-as-promised) | ||
![Dependency Status](https://david-dm.org/doublesharp/lru-cache-for-clusters-as-promised.svg) | ||
![Dev Dependency Status](https://david-dm.org/doublesharp/lru-cache-for-clusters-as-promised/dev-status.svg) | ||
![Downloads](https://img.shields.io/npm/dt/lru-cache-for-clusters-as-promised.svg) | ||
@@ -128,3 +126,6 @@ | ||
const LRUCache = require('lru-cache-for-clusters-as-promised'); | ||
const cache = new LRUCache({ | ||
// this is safe on the master and workers. if you need to ensure the underlying | ||
// LRUCache exists use `await getInstance()` to fetch the promisified cache. | ||
let cache = new LRUCache({ | ||
namespace: 'users', | ||
@@ -137,40 +138,39 @@ max: 50, | ||
// async cache | ||
(async function() { | ||
const options = { /* ...options */ }; | ||
const cache = await LRUCache.getInstance(options); | ||
}()); | ||
const user = { name: 'user name' }; | ||
const key = 'userKey'; | ||
// set a user for a the key | ||
cache.set(key, user) | ||
.then(() => { | ||
// using async/await | ||
(async function() { | ||
// get cache instance asynchronously. this will always be the same underlying cache | ||
cache = await LRUCache.getInstance({ /* ...options */ }); | ||
// set a user for a the key | ||
await cache.set(key, user); | ||
console.log('set the user to the cache'); | ||
// get the same user back out of the cache | ||
return cache.get(key); | ||
}) | ||
.then((cachedUser) => { | ||
// get the same user back out of the cache | ||
const cachedUser = await cache.get(key); | ||
console.log('got the user from cache', cachedUser); | ||
// check the number of users in the cache | ||
return cache.length(); | ||
}) | ||
.then((size) => { | ||
const size = await cache.length(); | ||
console.log('user cache size/length', size); | ||
// remove all the items from the cache | ||
return cache.reset(); | ||
}) | ||
.then(() => { | ||
await cache.reset(); | ||
console.log('the user cache is empty'); | ||
// return user count, this will return the same value as calling length() | ||
return cache.itemCount(); | ||
}) | ||
.then((size) => { | ||
console.log('user cache size/itemCount', size); | ||
}); | ||
const itemCount = await cache.itemCount(); | ||
console.log('user cache size/itemCount', itemCount); | ||
}()); | ||
// using thenables | ||
LRUCache.getInstance({ /* ...options */ }) | ||
.then((myCache) => | ||
myCache.set(key, user) | ||
.then(() => | ||
myCache.get(key) | ||
) | ||
) | ||
``` | ||
@@ -180,3 +180,3 @@ | ||
``` | ||
```javascript | ||
const flatted = require('flatted'); | ||
@@ -183,0 +183,0 @@ const LRUCache = require('lru-cache-for-clusters-as-promised'); |
@@ -12,33 +12,6 @@ const cluster = require('cluster'); | ||
// this is the path to the cluster worker that spawns the http server | ||
const workerPath = path.join(__dirname, 'cluster-worker.js'); | ||
cluster.setupMaster({ | ||
exec: path.join(__dirname, 'cluster-worker.js'), | ||
}); | ||
// we need to do some special things for coverages | ||
if (process.env.running_under_istanbul) { | ||
// use coverage for forked process | ||
// disabled reporting and output for child process | ||
// enable pid in child process coverage filename | ||
cluster.setupMaster({ | ||
exec: './node_modules/.bin/istanbul', | ||
args: [ | ||
'cover', | ||
'--report', | ||
'none', | ||
'--print', | ||
'none', | ||
// '--include-all-sources', | ||
// output files will have the workers PID in the filename | ||
'--include-pid', | ||
workerPath, | ||
'--', | ||
] | ||
// append any additional command line arguments | ||
.concat(process.argv.slice(2)), | ||
}); | ||
} else { | ||
// normal forking | ||
cluster.setupMaster({ | ||
exec: workerPath, | ||
}); | ||
} | ||
// start one worker to handle the threads | ||
@@ -45,0 +18,0 @@ const workers = 1; |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
82303
0
1653
+ Addeddebug@4.3.2(transitive)
- Removeddebug@4.3.1(transitive)
Updateddebug@4.3.2