petty-cache 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/eslint.config.js +44 -0
- package/index.js +18 -7
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.5.0] - 2025-05-01
|
|
10
|
+
### Changed
|
|
11
|
+
- Added the ability for `pettyCache.del` functions to support callbacks and promises.
|
|
12
|
+
|
|
9
13
|
## [3.4.0] - 2025-02-21
|
|
10
14
|
### Changed
|
|
11
15
|
- Added the ability for `pettyCache.mutex` functions to support callbacks and promises.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# petty-cache
|
|
2
2
|
|
|
3
|
-
[](https://github.com/mediocre/petty-cache/actions?query=workflow%3Abuild+branch%3Amain)
|
|
4
4
|
[](https://coveralls.io/github/mediocre/petty-cache?branch=main)
|
|
5
5
|
|
|
6
6
|
A cache module for Node.js that uses a two-level cache (in-memory cache for recently accessed data plus Redis for distributed caching) with automatic serialization plus some extra features to avoid cache stampedes and thundering herds.
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const globals = require('globals');
|
|
2
|
+
const js = require('@eslint/js');
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
js.configs.recommended,
|
|
6
|
+
{
|
|
7
|
+
ignores: ['node_modules/*'],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
ecmaVersion: 2020,
|
|
10
|
+
sourceType: 'module',
|
|
11
|
+
parserOptions: {
|
|
12
|
+
ecmaFeatures: {
|
|
13
|
+
jsx: true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
globals: {
|
|
17
|
+
...globals.es2020,
|
|
18
|
+
...globals.mocha,
|
|
19
|
+
...globals.node,
|
|
20
|
+
//added for 'fetch()' access
|
|
21
|
+
...globals.serviceworker
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
26
|
+
'comma-dangle': ['error', 'never'],
|
|
27
|
+
'dot-notation': 'error',
|
|
28
|
+
'no-array-constructor': 'error',
|
|
29
|
+
'no-console': 'error',
|
|
30
|
+
'no-fallthrough': 'off',
|
|
31
|
+
'no-inline-comments': 'warn',
|
|
32
|
+
'no-trailing-spaces': 'error',
|
|
33
|
+
'no-unused-vars': ['error', { caughtErrors: 'none' }],
|
|
34
|
+
'object-curly-spacing': ['error', 'always'],
|
|
35
|
+
quotes: ['error', 'single'],
|
|
36
|
+
semi: ['error', 'always'],
|
|
37
|
+
'space-before-function-paren': ['error', {
|
|
38
|
+
anonymous: 'never',
|
|
39
|
+
named: 'never',
|
|
40
|
+
asyncArrow: 'always'
|
|
41
|
+
}]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
];
|
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ function PettyCache() {
|
|
|
13
13
|
redisClient = redis.createClient(...arguments);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
//eslint-disable-next-line no-console
|
|
16
17
|
redisClient.on('error', err => console.warn(`Warning: Redis reported a client error: ${err}`));
|
|
17
18
|
|
|
18
19
|
function bulkGetFromRedis(keys, callback) {
|
|
@@ -254,14 +255,24 @@ function PettyCache() {
|
|
|
254
255
|
};
|
|
255
256
|
|
|
256
257
|
this.del = function(key, callback) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
const executor = () => {
|
|
259
|
+
return new Promise((resolve, reject) => {
|
|
260
|
+
redisClient.del(key, function(err) {
|
|
261
|
+
if (err) {
|
|
262
|
+
return reject(err);
|
|
263
|
+
}
|
|
261
264
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
memoryCache.del(key);
|
|
266
|
+
resolve();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
if (callback) {
|
|
272
|
+
executor().then(result => callback(null, result)).catch(callback);
|
|
273
|
+
} else {
|
|
274
|
+
return executor();
|
|
275
|
+
}
|
|
265
276
|
};
|
|
266
277
|
|
|
267
278
|
// Returns data from cache if available;
|
package/package.json
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
"redis": "~3.1.0"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
+
"@eslint/js": "*",
|
|
11
|
+
"globals": "*",
|
|
10
12
|
"coveralls": "*",
|
|
11
13
|
"mocha": "*",
|
|
12
14
|
"nyc": "*"
|
|
@@ -30,5 +32,5 @@
|
|
|
30
32
|
"type": "git",
|
|
31
33
|
"url": "https://github.com/mediocre/petty-cache.git"
|
|
32
34
|
},
|
|
33
|
-
"version": "3.
|
|
35
|
+
"version": "3.5.0"
|
|
34
36
|
}
|