@@ -31,59 +31,10 @@ const { homedir } = require('os')
3131const { depth } = require ( 'treeverse' )
3232const mapWorkspaces = require ( '@npmcli/map-workspaces' )
3333const { log, time } = require ( 'proc-log' )
34-
3534const { saveTypeMap } = require ( '../add-rm-pkg-deps.js' )
3635const AuditReport = require ( '../audit-report.js' )
3736const relpath = require ( '../relpath.js' )
38- const { LRUCache } = require ( 'lru-cache' )
39-
40- class PackumentCache extends LRUCache {
41- static #heapLimit = require ( 'node:v8' ) . getHeapStatistics ( ) . heap_size_limit
42-
43- #sizeKey
44- #disposed = new Set ( )
45-
46- #log ( ...args ) {
47- // It's all silly
48- log . silly ( 'packumentCache' , ...args )
49- }
50-
51- constructor ( { heapFactor = 0.25 , maxEntryFactor = 0.5 , sizeKey = '_contentLength' } = { } ) {
52- const maxSize = Math . floor ( PackumentCache . #heapLimit * heapFactor )
53- const maxEntrySize = maxSize * maxEntryFactor
54- super ( {
55- maxSize,
56- maxEntrySize,
57- // Don't cache if we dont know the size
58- sizeCalculation : ( p ) => p [ sizeKey ] || maxEntrySize + 1 ,
59- dispose : ( v , k ) => {
60- this . #disposed. add ( k )
61- this . #log( k , 'dispose' )
62- } ,
63- } )
64- this . #sizeKey = sizeKey
65- this . #log( `heap:${ PackumentCache . #heapLimit} maxSize:${ maxSize } maxEntrySize:${ maxEntrySize } ` )
66- }
67-
68- set ( k , v , ...args ) {
69- // we use disposed only for a logging signal if we are setting packuments that
70- // have already been evicted from the cache previously. logging here could help
71- // us tune this in the future.
72- const disposed = this . #disposed. has ( k )
73- /* istanbul ignore next - this doesnt happen consistently so hard to test without resorting to unit tests */
74- if ( disposed ) {
75- this . #disposed. delete ( k )
76- }
77- this . #log( k , 'set' , `size:${ v [ this . #sizeKey] } disposed:${ disposed } ` )
78- return super . set ( k , v , ...args )
79- }
80-
81- has ( k , ...args ) {
82- const has = super . has ( k , ...args )
83- this . #log( k , `cache-${ has ? 'hit' : 'miss' } ` )
84- return has
85- }
86- }
37+ const PackumentCache = require ( '../packument-cache.js' )
8738
8839const mixins = [
8940 require ( '../tracker.js' ) ,
0 commit comments