@atlaspack/cache 3.0.2-canary.2 → 3.0.2-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,13 @@ function _buildCache() {
12
12
  };
13
13
  return data;
14
14
  }
15
+ function _featureFlags() {
16
+ const data = require("@atlaspack/feature-flags");
17
+ _featureFlags = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
15
22
  function _rust() {
16
23
  const data = require("@atlaspack/rust");
17
24
  _rust = function () {
@@ -60,6 +67,12 @@ class LmdbWrapper {
60
67
  this.lmdb.close();
61
68
  };
62
69
  }
70
+ has(key) {
71
+ return this.lmdb.hasSync(key);
72
+ }
73
+ async delete(key) {
74
+ await this.lmdb.delete(key);
75
+ }
63
76
  get(key) {
64
77
  return this.lmdb.getSync(key);
65
78
  }
@@ -99,7 +112,9 @@ class LMDBLiteCache {
99
112
  return this.store.lmdb;
100
113
  }
101
114
  async ensure() {
102
- await this.fsCache.ensure();
115
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
116
+ await this.fsCache.ensure();
117
+ }
103
118
  return Promise.resolve();
104
119
  }
105
120
  serialize() {
@@ -111,7 +126,7 @@ class LMDBLiteCache {
111
126
  return new LMDBLiteCache(cache.dir);
112
127
  }
113
128
  has(key) {
114
- return Promise.resolve(this.store.get(key) != null);
129
+ return Promise.resolve(this.store.has(key));
115
130
  }
116
131
  get(key) {
117
132
  let data = this.store.get(key);
@@ -151,20 +166,40 @@ class LMDBLiteCache {
151
166
  return _path().default.join(this.dir, `${key}-${index}`);
152
167
  }
153
168
  hasLargeBlob(key) {
154
- return this.fs.exists(this.#getFilePath(key, 0));
169
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
170
+ return this.fsCache.hasLargeBlob(key);
171
+ }
172
+ return this.has(key);
155
173
  }
156
174
 
157
- // eslint-disable-next-line require-await
158
- async getLargeBlob(key) {
159
- return this.fsCache.getLargeBlob(key);
175
+ /**
176
+ * @deprecated Use getBlob instead.
177
+ */
178
+ getLargeBlob(key) {
179
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
180
+ return this.fsCache.getLargeBlob(key);
181
+ }
182
+ return Promise.resolve(this.getBlobSync(key));
160
183
  }
161
184
 
162
- // eslint-disable-next-line require-await
163
- async setLargeBlob(key, contents, options) {
164
- return this.fsCache.setLargeBlob(key, contents, options);
185
+ /**
186
+ * @deprecated Use setBlob instead.
187
+ */
188
+ setLargeBlob(key, contents, options) {
189
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
190
+ return this.fsCache.setLargeBlob(key, contents, options);
191
+ }
192
+ return this.setBlob(key, contents);
165
193
  }
194
+
195
+ /**
196
+ * @deprecated Use store.delete instead.
197
+ */
166
198
  deleteLargeBlob(key) {
167
- return this.fsCache.deleteLargeBlob(key);
199
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
200
+ return this.fsCache.deleteLargeBlob(key);
201
+ }
202
+ return this.store.delete(key);
168
203
  }
169
204
  refresh() {
170
205
  // Reset the read transaction for the store. This guarantees that
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaspack/cache",
3
3
  "description": "Interface for defining caches and file-system, IDB and LMDB implementations.",
4
- "version": "3.0.2-canary.2+1a2c14c3c",
4
+ "version": "3.0.2-canary.3+cb9da16fb",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "type": "commonjs",
7
7
  "publishConfig": {
@@ -23,11 +23,12 @@
23
23
  "check-ts": "tsc --noEmit index.d.ts"
24
24
  },
25
25
  "dependencies": {
26
- "@atlaspack/build-cache": "2.13.3-canary.65+1a2c14c3c",
27
- "@atlaspack/fs": "2.14.4-canary.2+1a2c14c3c",
28
- "@atlaspack/logger": "2.14.4-canary.2+1a2c14c3c",
29
- "@atlaspack/rust": "3.1.2-canary.2+1a2c14c3c",
30
- "@atlaspack/utils": "2.14.4-canary.2+1a2c14c3c"
26
+ "@atlaspack/build-cache": "2.13.3-canary.66+cb9da16fb",
27
+ "@atlaspack/feature-flags": "2.14.1-canary.66+cb9da16fb",
28
+ "@atlaspack/fs": "2.14.4-canary.3+cb9da16fb",
29
+ "@atlaspack/logger": "2.14.4-canary.3+cb9da16fb",
30
+ "@atlaspack/rust": "3.1.2-canary.3+cb9da16fb",
31
+ "@atlaspack/utils": "2.14.4-canary.3+cb9da16fb"
31
32
  },
32
33
  "devDependencies": {
33
34
  "idb": "^5.0.8"
@@ -35,5 +36,5 @@
35
36
  "browser": {
36
37
  "./src/IDBCache.js": "./src/IDBCache.browser.js"
37
38
  },
38
- "gitHead": "1a2c14c3cd4587551cc12e94d0680c8b71ea12bf"
39
+ "gitHead": "cb9da16fb2648e7f53c64df0313f60d5fb8970cc"
39
40
  }
@@ -5,6 +5,7 @@ import {
5
5
  registerSerializableClass,
6
6
  serialize,
7
7
  } from '@atlaspack/build-cache';
8
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
8
9
  import {Lmdb} from '@atlaspack/rust';
9
10
  import type {FilePath} from '@atlaspack/types';
10
11
  import type {Cache} from './types';
@@ -41,6 +42,14 @@ export class LmdbWrapper {
41
42
  };
42
43
  }
43
44
 
45
+ has(key: string): boolean {
46
+ return this.lmdb.hasSync(key);
47
+ }
48
+
49
+ async delete(key: string): Promise<void> {
50
+ await this.lmdb.delete(key);
51
+ }
52
+
44
53
  get(key: string): Buffer | null {
45
54
  return this.lmdb.getSync(key);
46
55
  }
@@ -105,7 +114,9 @@ export class LMDBLiteCache implements Cache {
105
114
  }
106
115
 
107
116
  async ensure(): Promise<void> {
108
- await this.fsCache.ensure();
117
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
118
+ await this.fsCache.ensure();
119
+ }
109
120
  return Promise.resolve();
110
121
  }
111
122
 
@@ -120,7 +131,7 @@ export class LMDBLiteCache implements Cache {
120
131
  }
121
132
 
122
133
  has(key: string): Promise<boolean> {
123
- return Promise.resolve(this.store.get(key) != null);
134
+ return Promise.resolve(this.store.has(key));
124
135
  }
125
136
 
126
137
  get<T>(key: string): Promise<?T> {
@@ -173,25 +184,45 @@ export class LMDBLiteCache implements Cache {
173
184
  }
174
185
 
175
186
  hasLargeBlob(key: string): Promise<boolean> {
176
- return this.fs.exists(this.#getFilePath(key, 0));
187
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
188
+ return this.fsCache.hasLargeBlob(key);
189
+ }
190
+ return this.has(key);
177
191
  }
178
192
 
179
- // eslint-disable-next-line require-await
180
- async getLargeBlob(key: string): Promise<Buffer> {
181
- return this.fsCache.getLargeBlob(key);
193
+ /**
194
+ * @deprecated Use getBlob instead.
195
+ */
196
+ getLargeBlob(key: string): Promise<Buffer> {
197
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
198
+ return this.fsCache.getLargeBlob(key);
199
+ }
200
+ return Promise.resolve(this.getBlobSync(key));
182
201
  }
183
202
 
184
- // eslint-disable-next-line require-await
185
- async setLargeBlob(
203
+ /**
204
+ * @deprecated Use setBlob instead.
205
+ */
206
+ setLargeBlob(
186
207
  key: string,
187
208
  contents: Buffer | string,
188
209
  options?: {|signal?: AbortSignal|},
189
210
  ): Promise<void> {
190
- return this.fsCache.setLargeBlob(key, contents, options);
211
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
212
+ return this.fsCache.setLargeBlob(key, contents, options);
213
+ }
214
+ return this.setBlob(key, contents);
191
215
  }
192
216
 
217
+ /**
218
+ * @deprecated Use store.delete instead.
219
+ */
193
220
  deleteLargeBlob(key: string): Promise<void> {
194
- return this.fsCache.deleteLargeBlob(key);
221
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
222
+ return this.fsCache.deleteLargeBlob(key);
223
+ }
224
+
225
+ return this.store.delete(key);
195
226
  }
196
227
 
197
228
  refresh(): void {