@trigo/atrix-acl
Advanced tools
@@ -5,9 +5,7 @@ 'use strict'; | ||
| const PARSER_CACHE = {}; | ||
| const MAX_CACHE_SIZE = 100; | ||
| let cacheKeys = []; | ||
| const MAX_MATCH_CACHE_SIZE = 10000; | ||
| class CachingRouteParser { | ||
| constructor(routeParser) { | ||
| this.MAX_CACHE_SIZE = 10000; | ||
| this.MATCH_CACHE = {}; | ||
@@ -19,8 +17,11 @@ this.cacheKeys = []; | ||
| match(path) { | ||
| if (this.MATCH_CACHE[path] !== undefined) return this.MATCH_CACHE[path]; | ||
| if (this.MATCH_CACHE[path] !== undefined) { | ||
| return this.MATCH_CACHE[path]; | ||
| } | ||
| if (this.cacheKeys.length === this.MAX_CACHE_SIZE) { | ||
| const tenPercent = Math.max(Math.ceil(this.MAX_CACHE_SIZE * 0.5), 1); | ||
| if (this.cacheKeys.length === MAX_MATCH_CACHE_SIZE) { | ||
| const tenPercent = Math.max(Math.ceil(MAX_MATCH_CACHE_SIZE * 0.1), 1); | ||
| console.log(`atrix-acl:RouteParser:CachingRouteParser: Reached max MATCH_CACHE size: ${MAX_MATCH_CACHE_SIZE}. Free cache ${tenPercent} items...`); | ||
| for (let i = 0; i < tenPercent; i++) { | ||
| this.MATCH_CACHE[this.cacheKeys[i]] = null; | ||
| this.MATCH_CACHE[this.cacheKeys[i]] = undefined; | ||
| } | ||
@@ -37,2 +38,5 @@ | ||
| const PARSER_CACHE = {}; | ||
| let cacheKeys = []; | ||
| module.exports = (route) => { | ||
@@ -42,11 +46,10 @@ if (PARSER_CACHE[route]) return PARSER_CACHE[route]; | ||
| if (cacheKeys.length === MAX_CACHE_SIZE) { | ||
| const tenPercent = Math.max(Math.ceil(MAX_CACHE_SIZE * 0.5), 1); | ||
| const tenPercent = Math.max(Math.ceil(MAX_CACHE_SIZE * 0.1), 1); | ||
| // console.log(`Reached max cache size: ${MAX_CACHE_SIZE}. Free cache ${tenPercent} items...`); | ||
| console.log(`atrix-acl:RouteParser: Reached max PARSER_CACHE size: ${MAX_CACHE_SIZE}. Free cache ${tenPercent} items...`); | ||
| for (let i = 0; i < tenPercent; i++) { | ||
| PARSER_CACHE[cacheKeys[i]] = null; | ||
| PARSER_CACHE[cacheKeys[i]] = undefined; | ||
| } | ||
| cacheKeys = cacheKeys.slice(tenPercent); | ||
| // console.log(`New cache size: ${cacheKeys.length}`); | ||
| } | ||
@@ -53,0 +56,0 @@ |
@@ -8,4 +8,4 @@ 'use strict'; | ||
| describe('route-parser', () => { | ||
| it.skip('uses constant max memory (SLOW!)', async () => { | ||
| describe.skip('route-parser', () => { | ||
| it('uses constant max memory (SLOW!)', async () => { | ||
| let iteration = 0; | ||
@@ -22,4 +22,5 @@ do { | ||
| iteration++; | ||
| console.log(`Finished iteration: ${iteration}`); | ||
| } while (iteration < 10000); | ||
| }); | ||
| }); |
+1
-1
| { | ||
| "name": "@trigo/atrix-acl", | ||
| "version": "3.12.2", | ||
| "version": "3.12.3", | ||
| "engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=7.6.0" |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
65245354
09319
0.03%