@fluidframework/driver-web-cache 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/driver-web-cache",
3
- "version": "2.0.0-internal.3.0.2",
3
+ "version": "2.0.0-internal.3.2.0",
4
4
  "description": "Implementation of the driver caching API for a web browser",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -14,41 +14,17 @@
14
14
  "main": "dist/index.js",
15
15
  "module": "lib/index.js",
16
16
  "types": "dist/index.d.ts",
17
- "scripts": {
18
- "build": "npm run build:genver && concurrently npm:build:compile npm:lint && npm run build:docs",
19
- "build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
20
- "build:compile": "concurrently npm:build:commonjs npm:build:esnext",
21
- "build:docs": "api-extractor run --local --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
22
- "build:esnext": "tsc --project ./tsconfig.esnext.json",
23
- "build:full": "npm run build",
24
- "build:full:compile": "npm run build:compile",
25
- "build:genver": "gen-version",
26
- "build:test": "tsc --project ./src/test/tsconfig.json",
27
- "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
28
- "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
29
- "eslint": "eslint --format stylish src",
30
- "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
31
- "format": "npm run prettier:fix",
32
- "lint": "npm run eslint",
33
- "lint:fix": "npm run eslint:fix",
34
- "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
35
- "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
36
- "test": "jest",
37
- "tsc": "tsc",
38
- "typetests:gen": "flub generate typetests --generate --dir .",
39
- "typetests:prepare": "flub generate typetests --prepare --dir . --pin"
40
- },
41
17
  "dependencies": {
42
18
  "@fluidframework/common-definitions": "^0.20.1",
43
- "@fluidframework/odsp-driver-definitions": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
44
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
19
+ "@fluidframework/odsp-driver-definitions": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
20
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
45
21
  "idb": "^6.1.2"
46
22
  },
47
23
  "devDependencies": {
48
- "@fluid-tools/build-cli": "^0.8.0",
24
+ "@fluid-tools/build-cli": "^0.10.0",
49
25
  "@fluidframework/build-common": "^1.1.0",
50
- "@fluidframework/build-tools": "^0.8.0",
51
- "@fluidframework/driver-web-cache-previous": "npm:@fluidframework/driver-web-cache@2.0.0-internal.3.0.0",
26
+ "@fluidframework/build-tools": "^0.10.0",
27
+ "@fluidframework/driver-web-cache-previous": "npm:@fluidframework/driver-web-cache@2.0.0-internal.3.1.0",
52
28
  "@fluidframework/eslint-config-fluid": "^2.0.0",
53
29
  "@microsoft/api-extractor": "^7.22.2",
54
30
  "@rushstack/eslint-config": "^2.5.1",
@@ -64,9 +40,34 @@
64
40
  "typescript": "~4.5.5"
65
41
  },
66
42
  "typeValidation": {
67
- "version": "2.0.0-internal.3.0.1",
68
- "previousVersionStyle": "previousPatch",
69
- "baselineRange": "2.0.0-internal.3.0.0",
43
+ "version": "2.0.0-internal.3.2.0",
44
+ "previousVersionStyle": "~previousMinor",
45
+ "baselineRange": ">=2.0.0-internal.3.1.0 <2.0.0-internal.3.2.0",
46
+ "baselineVersion": "2.0.0-internal.3.1.0",
70
47
  "broken": {}
48
+ },
49
+ "scripts": {
50
+ "build": "npm run build:genver && concurrently npm:build:compile npm:lint && npm run build:docs",
51
+ "build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
52
+ "build:compile": "concurrently npm:build:commonjs npm:build:esnext",
53
+ "build:docs": "api-extractor run --local --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
54
+ "build:esnext": "tsc --project ./tsconfig.esnext.json",
55
+ "build:full": "npm run build",
56
+ "build:full:compile": "npm run build:compile",
57
+ "build:genver": "gen-version",
58
+ "build:test": "tsc --project ./src/test/tsconfig.json",
59
+ "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
60
+ "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
61
+ "eslint": "eslint --format stylish src",
62
+ "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
63
+ "format": "npm run prettier:fix",
64
+ "lint": "npm run prettier && npm run eslint",
65
+ "lint:fix": "npm run prettier:fix && npm run eslint:fix",
66
+ "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
67
+ "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
68
+ "test": "jest",
69
+ "tsc": "tsc",
70
+ "typetests:gen": "flub generate typetests --generate --dir .",
71
+ "typetests:prepare": "flub generate typetests --prepare --dir . --pin"
71
72
  }
72
- }
73
+ }
@@ -4,5 +4,5 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- ...require("@fluidframework/build-common/prettier.config.cjs"),
7
+ ...require("@fluidframework/build-common/prettier.config.cjs"),
8
8
  };
package/src/FluidCache.ts CHANGED
@@ -3,274 +3,247 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import {
7
- IPersistedCache,
8
- ICacheEntry,
9
- IFileEntry,
10
- } from "@fluidframework/odsp-driver-definitions";
11
- import {
12
- ITelemetryBaseLogger,
13
- ITelemetryLogger,
14
- } from "@fluidframework/common-definitions";
6
+ import { IPersistedCache, ICacheEntry, IFileEntry } from "@fluidframework/odsp-driver-definitions";
7
+ import { ITelemetryBaseLogger, ITelemetryLogger } from "@fluidframework/common-definitions";
15
8
  import { ChildLogger } from "@fluidframework/telemetry-utils";
16
9
  import { scheduleIdleTask } from "./scheduleIdleTask";
17
10
  import {
18
- getFluidCacheIndexedDbInstance,
19
- FluidDriverObjectStoreName,
20
- getKeyForCacheEntry,
11
+ getFluidCacheIndexedDbInstance,
12
+ FluidDriverObjectStoreName,
13
+ getKeyForCacheEntry,
21
14
  } from "./FluidCacheIndexedDb";
22
15
  import {
23
- FluidCacheErrorEvent,
24
- FluidCacheEventSubCategories,
25
- FluidCacheGenericEvent,
16
+ FluidCacheErrorEvent,
17
+ FluidCacheEventSubCategories,
18
+ FluidCacheGenericEvent,
26
19
  } from "./fluidCacheTelemetry";
27
20
 
28
21
  // Some browsers have a usageDetails property that will tell you more detailed information
29
22
  // on how the storage is being used
30
23
  interface StorageQuotaUsageDetails {
31
- indexedDB: number | undefined;
24
+ indexedDB: number | undefined;
32
25
  }
33
26
 
34
27
  export interface FluidCacheConfig {
35
- /**
36
- * A string to specify what partition of the cache you wish to use (e.g. a user id).
37
- * Null can be used to explicity indicate no partitioning, and has been chosen
38
- * vs undefined so that it is clear this is an intentional choice by the caller.
39
- * A null value should only be used when the host can ensure that the cache is not able
40
- * to be shared with multiple users.
41
- */
42
- // eslint-disable-next-line @rushstack/no-new-null
43
- partitionKey: string | null;
44
-
45
- /**
46
- * A logger that can be used to get insight into cache performance and errors
47
- */
48
- logger?: ITelemetryBaseLogger;
49
-
50
- /**
51
- * A value in milliseconds that determines the maximum age of a cache entry to return.
52
- * If an entry exists in the cache, but is older than this value, the cached value will not be returned.
53
- */
54
- maxCacheItemAge: number;
28
+ /**
29
+ * A string to specify what partition of the cache you wish to use (e.g. a user id).
30
+ * Null can be used to explicity indicate no partitioning, and has been chosen
31
+ * vs undefined so that it is clear this is an intentional choice by the caller.
32
+ * A null value should only be used when the host can ensure that the cache is not able
33
+ * to be shared with multiple users.
34
+ */
35
+ // eslint-disable-next-line @rushstack/no-new-null
36
+ partitionKey: string | null;
37
+
38
+ /**
39
+ * A logger that can be used to get insight into cache performance and errors
40
+ */
41
+ logger?: ITelemetryBaseLogger;
42
+
43
+ /**
44
+ * A value in milliseconds that determines the maximum age of a cache entry to return.
45
+ * If an entry exists in the cache, but is older than this value, the cached value will not be returned.
46
+ */
47
+ maxCacheItemAge: number;
55
48
  }
56
49
 
57
50
  /**
58
51
  * A cache that can be used by the Fluid ODSP driver to cache data for faster performance
59
52
  */
60
53
  export class FluidCache implements IPersistedCache {
61
- private readonly logger: ITelemetryLogger;
62
-
63
- private readonly partitionKey: string | null;
64
-
65
- private readonly maxCacheItemAge: number;
66
-
67
- constructor(config: FluidCacheConfig) {
68
- this.logger = ChildLogger.create(config.logger);
69
- this.partitionKey = config.partitionKey;
70
- this.maxCacheItemAge = config.maxCacheItemAge;
71
-
72
- scheduleIdleTask(async () => {
73
- // Log how much storage space is currently being used by indexed db.
74
- // NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.
75
- // Exception added when eslint rule was added, this should be revisited when modifying this code
76
- if (navigator.storage?.estimate) {
77
- const estimate = await navigator.storage.estimate();
78
-
79
- // Some browsers have a usageDetails property that will tell you
80
- // more detailed information on how the storage is being used
81
- let indexedDBSize: number | undefined;
82
- if ("usageDetails" in estimate) {
83
- indexedDBSize = (
84
- (estimate as any)
85
- .usageDetails as StorageQuotaUsageDetails
86
- ).indexedDB;
87
- }
88
-
89
- this.logger.sendTelemetryEvent({
90
- eventName: FluidCacheGenericEvent.FluidCacheStorageInfo,
91
- subCategory: FluidCacheEventSubCategories.FluidCache,
92
- quota: estimate.quota,
93
- usage: estimate.usage,
94
- indexedDBSize,
95
- });
96
- }
97
- });
98
-
99
- scheduleIdleTask(async () => {
100
- // Delete entries that have not been accessed recently to clean up space
101
- try {
102
- const db = await getFluidCacheIndexedDbInstance(this.logger);
103
-
104
- const transaction = db.transaction(
105
- FluidDriverObjectStoreName,
106
- "readwrite",
107
- );
108
- const index = transaction.store.index("lastAccessTimeMs");
109
- // Get items that have not been accessed in 4 weeks
110
- const keysToDelete = await index.getAllKeys(
111
- IDBKeyRange.upperBound(
112
- new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000,
113
- ),
114
- );
115
-
116
- await Promise.all(
117
- keysToDelete.map((key) => transaction.store.delete(key)),
118
- );
119
- await transaction.done;
120
- } catch (error: any) {
121
- this.logger.sendErrorEvent(
122
- {
123
- eventName:
124
- FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,
125
- },
126
- error,
127
- );
128
- }
129
- });
130
- }
131
-
132
- public async removeEntries(file: IFileEntry): Promise<void> {
133
- try {
134
- const db = await getFluidCacheIndexedDbInstance(this.logger);
135
-
136
- const transaction = db.transaction(
137
- FluidDriverObjectStoreName,
138
- "readwrite",
139
- );
140
- const index = transaction.store.index("fileId");
141
-
142
- const keysToDelete = await index.getAllKeys(file.docId);
143
-
144
- await Promise.all(
145
- keysToDelete.map((key) => transaction.store.delete(key)),
146
- );
147
- await transaction.done;
148
- } catch (error: any) {
149
- this.logger.sendErrorEvent(
150
- {
151
- eventName:
152
- FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,
153
- },
154
- error,
155
- );
156
- }
157
- }
158
-
159
- public async get(cacheEntry: ICacheEntry): Promise<any> {
160
- const startTime = performance.now();
161
-
162
- const cachedItem = await this.getItemFromCache(cacheEntry);
163
-
164
- this.logger.sendPerformanceEvent({
165
- eventName: "FluidCacheAccess",
166
- cacheHit: cachedItem !== undefined,
167
- type: cacheEntry.type,
168
- duration: performance.now() - startTime,
169
- });
170
-
171
- // Value will contain metadata like the expiry time, we just want to return the object we were asked to cache
172
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
173
- return cachedItem?.cachedObject;
174
- }
175
-
176
- private async getItemFromCache(cacheEntry: ICacheEntry) {
177
- try {
178
- const key = getKeyForCacheEntry(cacheEntry);
179
-
180
- const db = await getFluidCacheIndexedDbInstance(this.logger);
181
-
182
- const value = await db.get(FluidDriverObjectStoreName, key);
183
-
184
- if (!value) {
185
- return undefined;
186
- }
187
-
188
- // If the data does not come from the same partition, don't return it
189
- if (value.partitionKey !== this.partitionKey) {
190
- this.logger.sendTelemetryEvent({
191
- eventName:
192
- FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,
193
- subCategory: FluidCacheEventSubCategories.FluidCache,
194
- });
195
-
196
- return undefined;
197
- }
198
-
199
- const currentTime = new Date().getTime();
200
-
201
- // If too much time has passed since this cache entry was used, we will also return undefined
202
- if (currentTime - value.createdTimeMs > this.maxCacheItemAge) {
203
- return undefined;
204
- }
205
-
206
- const transaction = db.transaction(
207
- FluidDriverObjectStoreName,
208
- "readwrite",
209
- );
210
- // We don't want to block the get return of this function on updating the last accessed time
211
- // We catch this promise because there is no user bad if this is rejected.
212
- transaction.store
213
- .get(key)
214
- .then(async (valueToUpdate) => {
215
- // This value in the database could have been updated concurrently by other tabs/iframes
216
- // since we first read it. Only update the last accessed time if the current value in the
217
- // DB was the same one we returned.
218
- if (
219
- valueToUpdate !== undefined &&
220
- valueToUpdate.createdTimeMs === value.createdTimeMs &&
221
- (valueToUpdate.lastAccessTimeMs === undefined ||
222
- valueToUpdate.lastAccessTimeMs < currentTime)
223
- ) {
224
- await transaction.store.put(
225
- { ...valueToUpdate, lastAccessTimeMs: currentTime },
226
- key,
227
- );
228
- }
229
- await transaction.done;
230
-
231
- db.close();
232
- })
233
- .catch(() => { });
234
- return value;
235
- } catch (error: any) {
236
- // We can fail to open the db for a variety of reasons,
237
- // such as the database version having upgraded underneath us. Return undefined in this case
238
- this.logger.sendErrorEvent(
239
- { eventName: FluidCacheErrorEvent.FluidCacheGetError },
240
- error,
241
- );
242
- return undefined;
243
- }
244
- }
245
-
246
- public async put(entry: ICacheEntry, value: any): Promise<void> {
247
- try {
248
- const db = await getFluidCacheIndexedDbInstance(this.logger);
249
-
250
- const currentTime = new Date().getTime();
251
-
252
- await db.put(
253
- FluidDriverObjectStoreName,
254
- {
255
- cachedObject: value,
256
- fileId: entry.file.docId,
257
- type: entry.type,
258
- cacheItemId: entry.key,
259
- partitionKey: this.partitionKey,
260
- createdTimeMs: currentTime,
261
- lastAccessTimeMs: currentTime,
262
- },
263
- getKeyForCacheEntry(entry),
264
- );
265
-
266
- db.close();
267
- } catch (error: any) {
268
- // We can fail to open the db for a variety of reasons,
269
- // such as the database version having upgraded underneath us
270
- this.logger.sendErrorEvent(
271
- { eventName: FluidCacheErrorEvent.FluidCachePutError },
272
- error,
273
- );
274
- }
275
- }
54
+ private readonly logger: ITelemetryLogger;
55
+
56
+ private readonly partitionKey: string | null;
57
+
58
+ private readonly maxCacheItemAge: number;
59
+
60
+ constructor(config: FluidCacheConfig) {
61
+ this.logger = ChildLogger.create(config.logger);
62
+ this.partitionKey = config.partitionKey;
63
+ this.maxCacheItemAge = config.maxCacheItemAge;
64
+
65
+ scheduleIdleTask(async () => {
66
+ // Log how much storage space is currently being used by indexed db.
67
+ // NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.
68
+ // Exception added when eslint rule was added, this should be revisited when modifying this code
69
+ if (navigator.storage?.estimate) {
70
+ const estimate = await navigator.storage.estimate();
71
+
72
+ // Some browsers have a usageDetails property that will tell you
73
+ // more detailed information on how the storage is being used
74
+ let indexedDBSize: number | undefined;
75
+ if ("usageDetails" in estimate) {
76
+ indexedDBSize = ((estimate as any).usageDetails as StorageQuotaUsageDetails)
77
+ .indexedDB;
78
+ }
79
+
80
+ this.logger.sendTelemetryEvent({
81
+ eventName: FluidCacheGenericEvent.FluidCacheStorageInfo,
82
+ subCategory: FluidCacheEventSubCategories.FluidCache,
83
+ quota: estimate.quota,
84
+ usage: estimate.usage,
85
+ indexedDBSize,
86
+ });
87
+ }
88
+ });
89
+
90
+ scheduleIdleTask(async () => {
91
+ // Delete entries that have not been accessed recently to clean up space
92
+ try {
93
+ const db = await getFluidCacheIndexedDbInstance(this.logger);
94
+
95
+ const transaction = db.transaction(FluidDriverObjectStoreName, "readwrite");
96
+ const index = transaction.store.index("lastAccessTimeMs");
97
+ // Get items that have not been accessed in 4 weeks
98
+ const keysToDelete = await index.getAllKeys(
99
+ IDBKeyRange.upperBound(new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000),
100
+ );
101
+
102
+ await Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));
103
+ await transaction.done;
104
+ } catch (error: any) {
105
+ this.logger.sendErrorEvent(
106
+ {
107
+ eventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,
108
+ },
109
+ error,
110
+ );
111
+ }
112
+ });
113
+ }
114
+
115
+ public async removeEntries(file: IFileEntry): Promise<void> {
116
+ try {
117
+ const db = await getFluidCacheIndexedDbInstance(this.logger);
118
+
119
+ const transaction = db.transaction(FluidDriverObjectStoreName, "readwrite");
120
+ const index = transaction.store.index("fileId");
121
+
122
+ const keysToDelete = await index.getAllKeys(file.docId);
123
+
124
+ await Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));
125
+ await transaction.done;
126
+ } catch (error: any) {
127
+ this.logger.sendErrorEvent(
128
+ {
129
+ eventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,
130
+ },
131
+ error,
132
+ );
133
+ }
134
+ }
135
+
136
+ public async get(cacheEntry: ICacheEntry): Promise<any> {
137
+ const startTime = performance.now();
138
+
139
+ const cachedItem = await this.getItemFromCache(cacheEntry);
140
+
141
+ this.logger.sendPerformanceEvent({
142
+ eventName: "FluidCacheAccess",
143
+ cacheHit: cachedItem !== undefined,
144
+ type: cacheEntry.type,
145
+ duration: performance.now() - startTime,
146
+ });
147
+
148
+ // Value will contain metadata like the expiry time, we just want to return the object we were asked to cache
149
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
150
+ return cachedItem?.cachedObject;
151
+ }
152
+
153
+ private async getItemFromCache(cacheEntry: ICacheEntry) {
154
+ try {
155
+ const key = getKeyForCacheEntry(cacheEntry);
156
+
157
+ const db = await getFluidCacheIndexedDbInstance(this.logger);
158
+
159
+ const value = await db.get(FluidDriverObjectStoreName, key);
160
+
161
+ if (!value) {
162
+ return undefined;
163
+ }
164
+
165
+ // If the data does not come from the same partition, don't return it
166
+ if (value.partitionKey !== this.partitionKey) {
167
+ this.logger.sendTelemetryEvent({
168
+ eventName: FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,
169
+ subCategory: FluidCacheEventSubCategories.FluidCache,
170
+ });
171
+
172
+ return undefined;
173
+ }
174
+
175
+ const currentTime = new Date().getTime();
176
+
177
+ // If too much time has passed since this cache entry was used, we will also return undefined
178
+ if (currentTime - value.createdTimeMs > this.maxCacheItemAge) {
179
+ return undefined;
180
+ }
181
+
182
+ const transaction = db.transaction(FluidDriverObjectStoreName, "readwrite");
183
+ // We don't want to block the get return of this function on updating the last accessed time
184
+ // We catch this promise because there is no user bad if this is rejected.
185
+ transaction.store
186
+ .get(key)
187
+ .then(async (valueToUpdate) => {
188
+ // This value in the database could have been updated concurrently by other tabs/iframes
189
+ // since we first read it. Only update the last accessed time if the current value in the
190
+ // DB was the same one we returned.
191
+ if (
192
+ valueToUpdate !== undefined &&
193
+ valueToUpdate.createdTimeMs === value.createdTimeMs &&
194
+ (valueToUpdate.lastAccessTimeMs === undefined ||
195
+ valueToUpdate.lastAccessTimeMs < currentTime)
196
+ ) {
197
+ await transaction.store.put(
198
+ { ...valueToUpdate, lastAccessTimeMs: currentTime },
199
+ key,
200
+ );
201
+ }
202
+ await transaction.done;
203
+
204
+ db.close();
205
+ })
206
+ .catch(() => {});
207
+ return value;
208
+ } catch (error: any) {
209
+ // We can fail to open the db for a variety of reasons,
210
+ // such as the database version having upgraded underneath us. Return undefined in this case
211
+ this.logger.sendErrorEvent(
212
+ { eventName: FluidCacheErrorEvent.FluidCacheGetError },
213
+ error,
214
+ );
215
+ return undefined;
216
+ }
217
+ }
218
+
219
+ public async put(entry: ICacheEntry, value: any): Promise<void> {
220
+ try {
221
+ const db = await getFluidCacheIndexedDbInstance(this.logger);
222
+
223
+ const currentTime = new Date().getTime();
224
+
225
+ await db.put(
226
+ FluidDriverObjectStoreName,
227
+ {
228
+ cachedObject: value,
229
+ fileId: entry.file.docId,
230
+ type: entry.type,
231
+ cacheItemId: entry.key,
232
+ partitionKey: this.partitionKey,
233
+ createdTimeMs: currentTime,
234
+ lastAccessTimeMs: currentTime,
235
+ },
236
+ getKeyForCacheEntry(entry),
237
+ );
238
+
239
+ db.close();
240
+ } catch (error: any) {
241
+ // We can fail to open the db for a variety of reasons,
242
+ // such as the database version having upgraded underneath us
243
+ this.logger.sendErrorEvent(
244
+ { eventName: FluidCacheErrorEvent.FluidCachePutError },
245
+ error,
246
+ );
247
+ }
248
+ }
276
249
  }