MCPcopy Index your code
hub / github.com/nodejs/node / constructor

Method constructor

deps/undici/src/lib/cache/sqlite-cache-store.js:78–224  ·  view source on GitHub ↗

* @param {import('../../types/cache-interceptor.d.ts').default.SqliteCacheStoreOpts | undefined} opts

(opts)

Source from the content-addressed store, hash-verified

76 * @param {import('../../types/cache-interceptor.d.ts').default.SqliteCacheStoreOpts | undefined} opts
77 */
78 constructor (opts) {
79 if (opts) {
80 if (typeof opts !== 'object') {
81 throw new TypeError('SqliteCacheStore options must be an object')
82 }
83
84 if (opts.maxEntrySize !== undefined) {
85 if (
86 typeof opts.maxEntrySize !== 'number' ||
87 !Number.isInteger(opts.maxEntrySize) ||
88 opts.maxEntrySize < 0
89 ) {
90 throw new TypeError('SqliteCacheStore options.maxEntrySize must be a non-negative integer')
91 }
92
93 if (opts.maxEntrySize > MAX_ENTRY_SIZE) {
94 throw new TypeError('SqliteCacheStore options.maxEntrySize must be less than 2gb')
95 }
96
97 this.#maxEntrySize = opts.maxEntrySize
98 }
99
100 if (opts.maxCount !== undefined) {
101 if (
102 typeof opts.maxCount !== 'number' ||
103 !Number.isInteger(opts.maxCount) ||
104 opts.maxCount < 0
105 ) {
106 throw new TypeError('SqliteCacheStore options.maxCount must be a non-negative integer')
107 }
108 this.#maxCount = opts.maxCount
109 }
110 }
111
112 if (!DatabaseSync) {
113 DatabaseSync = require('node:sqlite').DatabaseSync
114 }
115 this.#db = new DatabaseSync(opts?.location ?? ':memory:')
116
117 this.#db.exec(`
118 PRAGMA journal_mode = WAL;
119 PRAGMA synchronous = NORMAL;
120 PRAGMA temp_store = memory;
121 PRAGMA optimize;
122
123 CREATE TABLE IF NOT EXISTS cacheInterceptorV${VERSION} (
124 -- Data specific to us
125 id INTEGER PRIMARY KEY AUTOINCREMENT,
126 url TEXT NOT NULL,
127 method TEXT NOT NULL,
128
129 -- Data returned to the interceptor
130 body BUF NULL,
131 deleteAt INTEGER NOT NULL,
132 statusCode INTEGER NOT NULL,
133 statusMessage TEXT NOT NULL,
134 headers TEXT NULL,
135 cacheControlDirectives TEXT NULL,

Callers

nothing calls this directly

Calls 3

requireFunction · 0.50
execMethod · 0.45
prepareMethod · 0.45

Tested by

no test coverage detected