cluster-shared-cache
Advanced tools
+22
| export interface ClusterSharedCacheOptions { | ||
| maxSize?: number; | ||
| ttl?: number; | ||
| checkPeriod?: number; | ||
| } | ||
| export declare class ClusterSharedCache { | ||
| constructor(options?: ClusterSharedCacheOptions); | ||
| set(key: string, value: any, ttl?: number): Promise<void>; | ||
| get(key: string): Promise<any>; | ||
| delete(key: string): Promise<void>; | ||
| clear(): Promise<void>; | ||
| has(key: string): boolean; | ||
| size(): number; | ||
| keys(): string[]; | ||
| values(): any[]; | ||
| entries(): [string, any][]; | ||
| destroy(): void; | ||
| } | ||
| export = ClusterSharedCache; |
+29
-12
| { | ||
| "name": "cluster-shared-cache", | ||
| "version": "1.0.2", | ||
| "description": "Handling shared in memory cache in node js cluster module", | ||
| "version": "1.0.3", | ||
| "description": "A shared in-memory cache for Node.js cluster applications", | ||
| "main": "index.js", | ||
| "types": "index.d.ts", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "keywords": [ | ||
| "cache", | ||
| "node-js", | ||
| "in-memory", | ||
| "cluster", | ||
| "cluster", | ||
| "nodejs", | ||
@@ -18,10 +17,28 @@ "memory", | ||
| "shared", | ||
| "express" | ||
| "express", | ||
| "typescript" | ||
| ], | ||
| "author": "shikhkarim", | ||
| "license": "ISC", | ||
| "author": "Your Name", | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=12.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^9.35.0", | ||
| "jest": "^30.1.3" | ||
| "jest": "^29.0.0", | ||
| "eslint": "^8.0.0", | ||
| "@types/node": "^20.0.0" | ||
| }, | ||
| "files": [ | ||
| "index.js", | ||
| "index.d.ts", | ||
| "README.md", | ||
| "LICENSE" | ||
| ], | ||
| "exports": { | ||
| ".": { | ||
| "types": "./index.d.ts", | ||
| "require": "./index.js", | ||
| "import": "./index.js" | ||
| } | ||
| } | ||
| } | ||
| } |
| const ClusterSharedCache = require('../index'); | ||
| const cluster = require('cluster'); | ||
| async function runBenchmark() { | ||
| const cache = new ClusterSharedCache({ maxSize: 1000 }); | ||
| console.log('Starting performance benchmark...'); | ||
| console.log('Testing SET operations...'); | ||
| const setStart = Date.now(); | ||
| const setPromises = []; | ||
| for (let i = 0; i < 1000; i++) { | ||
| setPromises.push(cache.set(`key_${i}`, { id: i, data: `value_${i}`, timestamp: Date.now() })); | ||
| } | ||
| await Promise.all(setPromises); | ||
| const setTime = Date.now() - setStart; | ||
| console.log(`SET: 1000 operations in ${setTime}ms (${(1000/setTime*1000).toFixed(2)} ops/sec)`); | ||
| // Test GET operations | ||
| console.log('Testing GET operations...'); | ||
| const getStart = Date.now(); | ||
| const getPromises = []; | ||
| for (let i = 0; i < 1000; i++) { | ||
| getPromises.push(cache.get(`key_${i}`)); | ||
| } | ||
| const results = await Promise.all(getPromises); | ||
| const getTime = Date.now() - getStart; | ||
| const hits = results.filter(r => r !== undefined).length; | ||
| console.log(`GET: 1000 operations in ${getTime}ms (${(1000/getTime*1000).toFixed(2)} ops/sec)`); | ||
| console.log(`Cache hit rate: ${hits}/1000 (${(hits/1000*100).toFixed(1)}%)`); | ||
| // Test mixed operations | ||
| console.log('Testing mixed operations...'); | ||
| const mixedStart = Date.now(); | ||
| const mixedPromises = []; | ||
| for (let i = 0; i < 500; i++) { | ||
| const rand = Math.random(); | ||
| if (rand < 0.7) { | ||
| mixedPromises.push(cache.get(`key_${Math.floor(Math.random() * 1000)}`)); | ||
| } else if (rand < 0.95) { | ||
| mixedPromises.push(cache.set(`key_${Math.floor(Math.random() * 1000)}`, { mixed: true })); | ||
| } else { | ||
| mixedPromises.push(cache.delete(`key_${Math.floor(Math.random() * 1000)}`)); | ||
| } | ||
| } | ||
| await Promise.all(mixedPromises); | ||
| const mixedTime = Date.now() - mixedStart; | ||
| console.log(`ā Mixed: 500 operations in ${mixedTime}ms (${(500/mixedTime*1000).toFixed(2)} ops/sec)`); | ||
| console.log('\nš Memory usage:'); | ||
| console.log(`Cache size: ${cache.size()} items`); | ||
| console.log(`Memory usage: ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`); | ||
| cache.destroy(); | ||
| console.log('\nā Benchmark completed!'); | ||
| } | ||
| if (require.main === module) { | ||
| runBenchmark().catch(console.error); | ||
| } |
| export interface ClusterSharedCacheOptions { | ||
| maxSize?: number; | ||
| ttl?: number; | ||
| checkPeriod?: number; | ||
| } | ||
| export declare class ClusterSharedCache { | ||
| constructor(options?: ClusterSharedCacheOptions); | ||
| set(key: string, value: any, ttl?: number): Promise<void>; | ||
| get(key: string): Promise<any>; | ||
| delete(key: string): Promise<void>; | ||
| clear(): Promise<void>; | ||
| has(key: string): boolean; | ||
| size(): number; | ||
| keys(): string[]; | ||
| values(): any[]; | ||
| entries(): [string, any][]; | ||
| destroy(): void; | ||
| } | ||
| export = ClusterSharedCache; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
-50%0
-100%9999
-16.89%3
50%3
-25%328
-13.46%