MCPcopy
hub / github.com/nodejs/undici / MemoryCacheStore

Class MemoryCacheStore

lib/cache/memory-cache-store.js:18–218  ·  view source on GitHub ↗

* @implements {CacheStore} * @extends {EventEmitter}

Source from the content-addressed store, hash-verified

16 * @extends {EventEmitter}
17 */
18class MemoryCacheStore extends EventEmitter {
19 #maxCount = 1024
20 #maxSize = 104857600 // 100MB
21 #maxEntrySize = 5242880 // 5MB
22
23 #size = 0
24 #count = 0
25 #entries = new Map()
26 #hasEmittedMaxSizeEvent = false
27
28 /**
29 * @param {import('../../types/cache-interceptor.d.ts').default.MemoryCacheStoreOpts | undefined} [opts]
30 */
31 constructor (opts) {
32 super()
33 if (opts) {
34 if (typeof opts !== 'object') {
35 throw new TypeError('MemoryCacheStore options must be an object')
36 }
37
38 if (opts.maxCount !== undefined) {
39 if (
40 typeof opts.maxCount !== 'number' ||
41 !Number.isInteger(opts.maxCount) ||
42 opts.maxCount < 0
43 ) {
44 throw new TypeError('MemoryCacheStore options.maxCount must be a non-negative integer')
45 }
46 this.#maxCount = opts.maxCount
47 }
48
49 if (opts.maxSize !== undefined) {
50 if (
51 typeof opts.maxSize !== 'number' ||
52 !Number.isInteger(opts.maxSize) ||
53 opts.maxSize < 0
54 ) {
55 throw new TypeError('MemoryCacheStore options.maxSize must be a non-negative integer')
56 }
57 this.#maxSize = opts.maxSize
58 }
59
60 if (opts.maxEntrySize !== undefined) {
61 if (
62 typeof opts.maxEntrySize !== 'number' ||
63 !Number.isInteger(opts.maxEntrySize) ||
64 opts.maxEntrySize < 0
65 ) {
66 throw new TypeError('MemoryCacheStore options.maxEntrySize must be a non-negative integer')
67 }
68 this.#maxEntrySize = opts.maxEntrySize
69 }
70 }
71 }
72
73 /**
74 * Get the current size of the cache in bytes
75 * @returns {number} The current size of the cache in bytes

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…