@fluidframework/driver-web-cache 2.61.0 → 2.62.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @fluidframework/driver-web-cache
2
2
 
3
+ ## 2.62.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Move IPersistedCache types to driver-definitions ([#25518](https://github.com/microsoft/FluidFramework/pull/25518)) [54fca68d91](https://github.com/microsoft/FluidFramework/commit/54fca68d91aeb40bdef14b1fe8b8f3c28168b6de)
8
+
9
+ In an effort to decouple the driver web cache from the odsp driver a number of types have been moved from `@fluidframework/odsp-driver-definitions` to `@fluidframework/driver-definitions`. The moved types have been deprecated in `@fluidframework/odsp-driver-definitions`, and any usages should be moved to `@fluidframework/driver-definitions`.
10
+
11
+ The moved types are:
12
+
13
+ - `IEntry`
14
+ - `IFileEntry`
15
+ - `ICacheEntry`
16
+ - `IPersistedCache`
17
+
3
18
  ## 2.61.0
4
19
 
5
20
  Dependency updates only.
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { ICacheEntry, IFileEntry, IPersistedCache } from "@fluidframework/odsp-driver-definitions/internal";
6
+ import type { IPersistedCache, IFileEntry, ICacheEntry } from "@fluidframework/driver-definitions/internal";
7
7
  /**
8
8
  * @legacy @beta
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.d.ts","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EACN,WAAW,EACX,UAAU,EACV,eAAe,EAEf,MAAM,kDAAkD,CAAC;AA4B1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IAEH,YAAY,EAAE,MAAM,GAAG,IAA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;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,UAAW,YAAW,eAAe;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiB;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,EAAE,CAA+C;IACzD,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,YAAY,CAAc;gBAEtB,MAAM,EAAE,gBAAgB;YAqFtB,MAAM;IAwCpB,OAAO,CAAC,OAAO;IAMF,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9C,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAoBzC,gBAAgB;IAiDjB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAgC/D"}
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.FluidCache = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
- const internal_2 = require("@fluidframework/odsp-driver-definitions/internal");
9
+ const internal_2 = require("@fluidframework/driver-utils/internal");
10
10
  const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
11
  const FluidCacheIndexedDb_js_1 = require("./FluidCacheIndexedDb.js");
12
12
  const packageVersion_js_1 = require("./packageVersion.js");
@@ -170,7 +170,7 @@ class FluidCache {
170
170
  async getItemFromCache(cacheEntry) {
171
171
  let db;
172
172
  try {
173
- const key = (0, FluidCacheIndexedDb_js_1.getKeyForCacheEntry)(cacheEntry);
173
+ const key = (0, internal_2.getKeyForCacheEntry)(cacheEntry);
174
174
  const dbOpenStartTime = performance.now();
175
175
  db = await this.openDb();
176
176
  const dbOpenPerf = performance.now() - dbOpenStartTime;
@@ -219,7 +219,7 @@ class FluidCache {
219
219
  partitionKey: this.partitionKey,
220
220
  createdTimeMs: currentTime,
221
221
  lastAccessTimeMs: currentTime,
222
- }, (0, FluidCacheIndexedDb_js_1.getKeyForCacheEntry)(entry));
222
+ }, (0, internal_2.getKeyForCacheEntry)(entry));
223
223
  this.closeDb(db);
224
224
  }
225
225
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAC7D,+EAK0D;AAC1D,uEAIkD;AAGlD,qEAKkC;AAMlC,2DAAiD;AACjD,+DAAyD;AAwCzD;;;GAGG;AACH,MAAa,UAAU;IAYtB,YAAY,MAAwB;QANnB,uBAAkB,GAAY,IAAI,CAAC;QAI5C,iBAAY,GAAW,CAAC,CAAC,CAAC;QAGjC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QACzE,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,eAAe,GAAG,iCAAsB,EAAE,CAAC;YAC9C,MAAM,KAAK,GAAG,IAAI,qBAAU,CAC3B,mBAAmB,eAAe,4BAA4B,iCAAsB,EAAE,EACtF;gBACC,eAAe;gBACf,sBAAsB,EAAtB,iCAAsB;gBACtB,UAAU,EAAV,8BAAU;aACV,CACD,CAAC;YACF,gDAAgD;YAChD,0CAA0C;YAC1C,IAAI,CAAC,MAAM,CAAC,cAAc,CACzB;gBACC,SAAS,EAAE,yBAAyB;gBACpC,WAAW,4DAAyC;aACpD,EACD,KAAK,CACL,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AI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;CACD;AA7QD,gCA6QC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tICacheEntry,\n\tIFileEntry,\n\tIPersistedCache,\n\tmaximumCacheDurationMs,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { IDBPDatabase } from \"idb\";\n\nimport {\n\tFluidCacheDBSchema,\n\tFluidDriverObjectStoreName,\n\tgetFluidCacheIndexedDbInstance,\n\tgetKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb.js\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask.js\";\n\n// Some browsers have a usageDetails property that will tell you more detailed information\n// on how the storage is being used\ninterface StorageQuotaUsageDetails {\n\tindexedDB: number | undefined;\n}\n\n/**\n * @legacy @beta\n */\nexport interface FluidCacheConfig {\n\t/**\n\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t * Null can be used to explicity indicate no partitioning, and has been chosen\n\t * vs undefined so that it is clear this is an intentional choice by the caller.\n\t * A null value should only be used when the host can ensure that the cache is not able\n\t * to be shared with multiple users.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpartitionKey: string | null;\n\n\t/**\n\t * A logger that can be used to get insight into cache performance and errors\n\t */\n\tlogger?: ITelemetryBaseLogger;\n\n\t/**\n\t * A value in milliseconds that determines the maximum age of a cache entry to return.\n\t * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n\t */\n\tmaxCacheItemAge: number;\n\n\t/**\n\t * Each time db is opened, it will remain open for this much time. To improve perf, if this property is set as\n\t * any number greater than 0, then db will not be closed immediately after usage. This value is in milliseconds.\n\t */\n\tcloseDbAfterMs?: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance.\n * @legacy @beta\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\tprivate readonly closeDbImmediately: boolean = true;\n\tprivate readonly closeDbAfterMs: number;\n\tprivate db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\tprivate dbCloseTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate dbReuseCount: number = -1;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tconst { logger, partitionKey, maxCacheItemAge, closeDbAfterMs } = config;\n\t\tthis.logger = createChildLogger({ logger });\n\t\tthis.partitionKey = partitionKey;\n\t\tif (maxCacheItemAge > maximumCacheDurationMs) {\n\t\t\tconst error = new UsageError(\n\t\t\t\t`maxCacheItemAge(${maxCacheItemAge}) cannot be greater than ${maximumCacheDurationMs}`,\n\t\t\t\t{\n\t\t\t\t\tmaxCacheItemAge,\n\t\t\t\t\tmaximumCacheDurationMs,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// go with logging, rather than throwing for now\n\t\t\t// as throwing could break existing usages\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"maxCacheItemAgeTooLarge\",\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t\tthis.maxCacheItemAge = Math.min(maxCacheItemAge, maximumCacheDurationMs);\n\t\tthis.closeDbAfterMs = closeDbAfterMs ?? 0;\n\t\tif (this.closeDbAfterMs > 0) {\n\t\t\tthis.closeDbImmediately = false;\n\t\t}\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Log how much storage space is currently being used by indexed db.\n\t\t\t// NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n\t\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\t\tif (navigator.storage?.estimate) {\n\t\t\t\tconst estimate = await navigator.storage.estimate();\n\n\t\t\t\t// Some browsers have a usageDetails property that will tell you\n\t\t\t\t// more detailed information on how the storage is being used\n\t\t\t\tlet indexedDBSize: number | undefined;\n\t\t\t\tif (\"usageDetails\" in estimate) {\n\t\t\t\t\tindexedDBSize = ((estimate as any).usageDetails as StorageQuotaUsageDetails)\n\t\t\t\t\t\t.indexedDB;\n\t\t\t\t}\n\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tquota: estimate.quota,\n\t\t\t\t\tusage: estimate.usage,\n\t\t\t\t\tindexedDBSize,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tdb = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"createdTimeMs\");\n\t\t\t\t// Get items which were cached before the maxCacheItemAge.\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - this.maxCacheItemAge),\n\t\t\t\t);\n\n\t\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\t\tawait transaction.done;\n\t\t\t} catch (error: any) {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\t\tpkgVersion,\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t} finally {\n\t\t\t\tdb?.close();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async openDb() {\n\t\tif (this.closeDbImmediately) {\n\t\t\treturn getFluidCacheIndexedDbInstance(this.logger);\n\t\t}\n\t\tif (this.db === undefined) {\n\t\t\tconst dbInstance = await getFluidCacheIndexedDbInstance(this.logger);\n\t\t\tif (this.db === undefined) {\n\t\t\t\t// Reset the counter on first open.\n\t\t\t\tthis.dbReuseCount = -1;\n\t\t\t\tthis.db = dbInstance;\n\t\t\t} else {\n\t\t\t\tdbInstance.close();\n\t\t\t\tthis.dbReuseCount += 1;\n\t\t\t\treturn this.db;\n\t\t\t}\n\t\t\t// Need to close the db on version change if opened.\n\t\t\tthis.db.onversionchange = (ev) => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t};\n\t\t\tthis.db.addEventListener(\"close\", (ev) => {\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t\tthis.db = undefined;\n\t\t\t});\n\t\t\t// Schedule db close after this.closeDbAfterMs.\n\t\t\tassert(this.dbCloseTimer === undefined, 0x6c6 /* timer should not be set yet!! */);\n\t\t\tthis.dbCloseTimer = setTimeout(() => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t}, this.closeDbAfterMs);\n\t\t}\n\t\tassert(this.db !== undefined, 0x6c7 /* db should be intialized by now */);\n\t\tthis.dbReuseCount += 1;\n\t\treturn this.db;\n\t}\n\n\tprivate closeDb(db?: IDBPDatabase<FluidCacheDBSchema>) {\n\t\tif (this.closeDbImmediately) {\n\t\t\tdb?.close();\n\t\t}\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\tconst index = transaction.store.index(\"fileId\");\n\n\t\t\tconst keysToDelete = await index.getAllKeys(file.docId);\n\n\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\tawait transaction.done;\n\t\t} catch (error: any) {\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n\n\tpublic async get(cacheEntry: ICacheEntry): Promise<any> {\n\t\tconst startTime = performance.now();\n\n\t\tconst cachedItem = await this.getItemFromCache(cacheEntry);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"FluidCacheAccess\",\n\t\t\tcacheHit: cachedItem !== undefined,\n\t\t\ttype: cacheEntry.type,\n\t\t\tduration: performance.now() - startTime,\n\t\t\tdbOpenPerf: cachedItem?.dbOpenPerf,\n\t\t\tdbReuseCount: this.dbReuseCount,\n\t\t\tpkgVersion,\n\t\t});\n\n\t\t// Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn cachedItem?.cachedObject;\n\t}\n\n\tprivate async getItemFromCache(cacheEntry: ICacheEntry) {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst dbOpenStartTime = performance.now();\n\t\t\tdb = await this.openDb();\n\t\t\tconst dbOpenPerf = performance.now() - dbOpenStartTime;\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// If the data does not come from the same partition, don't return it\n\t\t\tif (value.partitionKey !== this.partitionKey) {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\t// If too much time has passed since this cache entry was used, we will also return undefined\n\t\t\tif (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tthis.closeDb(db);\n\t\t\treturn { ...value, dbOpenPerf };\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us. Return undefined in this case\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCacheGetError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\tawait db.put(\n\t\t\t\tFluidDriverObjectStoreName,\n\t\t\t\t{\n\t\t\t\t\tcachedObject: value,\n\t\t\t\t\tfileId: entry.file.docId,\n\t\t\t\t\ttype: entry.type,\n\t\t\t\t\tcacheItemId: entry.key,\n\t\t\t\t\tpartitionKey: this.partitionKey,\n\t\t\t\t\tcreatedTimeMs: currentTime,\n\t\t\t\t\tlastAccessTimeMs: currentTime,\n\t\t\t\t},\n\t\t\t\tgetKeyForCacheEntry(entry),\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCachePutError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAM7D,oEAG+C;AAC/C,uEAIkD;AAGlD,qEAIkC;AAMlC,2DAAiD;AACjD,+DAAyD;AAwCzD;;;GAGG;AACH,MAAa,UAAU;IAYtB,YAAY,MAAwB;QANnB,uBAAkB,GAAY,IAAI,CAAC;QAI5C,iBAAY,GAAW,CAAC,CAAC,CAAC;QAGjC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QACzE,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,eAAe,GAAG,iCAAsB,EAAE,CAAC;YAC9C,MAAM,KAAK,GAAG,IAAI,qBAAU,CAC3B,mBAAmB,eAAe,4BAA4B,iCAAsB,EAAE,EACtF;gBACC,eAAe;gBACf,sBAAsB,EAAtB,iCAAsB;gBACtB,UAAU,EAAV,8BAAU;aACV,CACD,CAAC;YACF,gDAAgD;YAChD,0CAA0C;YAC1C,IAAI,CAAC,MAAM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yC,EAAE,UAAU,EAAV,8BAAU,EAAE,EAClE,KAAK,CACL,CAAC;QACH,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;CACD;AA7QD,gCA6QC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIPersistedCache,\n\tIFileEntry,\n\tICacheEntry,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tgetKeyForCacheEntry,\n\tmaximumCacheDurationMs,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { IDBPDatabase } from \"idb\";\n\nimport {\n\tFluidCacheDBSchema,\n\tFluidDriverObjectStoreName,\n\tgetFluidCacheIndexedDbInstance,\n} from \"./FluidCacheIndexedDb.js\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask.js\";\n\n// Some browsers have a usageDetails property that will tell you more detailed information\n// on how the storage is being used\ninterface StorageQuotaUsageDetails {\n\tindexedDB: number | undefined;\n}\n\n/**\n * @legacy @beta\n */\nexport interface FluidCacheConfig {\n\t/**\n\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t * Null can be used to explicity indicate no partitioning, and has been chosen\n\t * vs undefined so that it is clear this is an intentional choice by the caller.\n\t * A null value should only be used when the host can ensure that the cache is not able\n\t * to be shared with multiple users.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpartitionKey: string | null;\n\n\t/**\n\t * A logger that can be used to get insight into cache performance and errors\n\t */\n\tlogger?: ITelemetryBaseLogger;\n\n\t/**\n\t * A value in milliseconds that determines the maximum age of a cache entry to return.\n\t * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n\t */\n\tmaxCacheItemAge: number;\n\n\t/**\n\t * Each time db is opened, it will remain open for this much time. To improve perf, if this property is set as\n\t * any number greater than 0, then db will not be closed immediately after usage. This value is in milliseconds.\n\t */\n\tcloseDbAfterMs?: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance.\n * @legacy @beta\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\tprivate readonly closeDbImmediately: boolean = true;\n\tprivate readonly closeDbAfterMs: number;\n\tprivate db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\tprivate dbCloseTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate dbReuseCount: number = -1;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tconst { logger, partitionKey, maxCacheItemAge, closeDbAfterMs } = config;\n\t\tthis.logger = createChildLogger({ logger });\n\t\tthis.partitionKey = partitionKey;\n\t\tif (maxCacheItemAge > maximumCacheDurationMs) {\n\t\t\tconst error = new UsageError(\n\t\t\t\t`maxCacheItemAge(${maxCacheItemAge}) cannot be greater than ${maximumCacheDurationMs}`,\n\t\t\t\t{\n\t\t\t\t\tmaxCacheItemAge,\n\t\t\t\t\tmaximumCacheDurationMs,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// go with logging, rather than throwing for now\n\t\t\t// as throwing could break existing usages\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"maxCacheItemAgeTooLarge\",\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t\tthis.maxCacheItemAge = Math.min(maxCacheItemAge, maximumCacheDurationMs);\n\t\tthis.closeDbAfterMs = closeDbAfterMs ?? 0;\n\t\tif (this.closeDbAfterMs > 0) {\n\t\t\tthis.closeDbImmediately = false;\n\t\t}\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Log how much storage space is currently being used by indexed db.\n\t\t\t// NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n\t\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\t\tif (navigator.storage?.estimate) {\n\t\t\t\tconst estimate = await navigator.storage.estimate();\n\n\t\t\t\t// Some browsers have a usageDetails property that will tell you\n\t\t\t\t// more detailed information on how the storage is being used\n\t\t\t\tlet indexedDBSize: number | undefined;\n\t\t\t\tif (\"usageDetails\" in estimate) {\n\t\t\t\t\tindexedDBSize = ((estimate as any).usageDetails as StorageQuotaUsageDetails)\n\t\t\t\t\t\t.indexedDB;\n\t\t\t\t}\n\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tquota: estimate.quota,\n\t\t\t\t\tusage: estimate.usage,\n\t\t\t\t\tindexedDBSize,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tdb = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"createdTimeMs\");\n\t\t\t\t// Get items which were cached before the maxCacheItemAge.\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - this.maxCacheItemAge),\n\t\t\t\t);\n\n\t\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\t\tawait transaction.done;\n\t\t\t} catch (error: any) {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\t\tpkgVersion,\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t} finally {\n\t\t\t\tdb?.close();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async openDb() {\n\t\tif (this.closeDbImmediately) {\n\t\t\treturn getFluidCacheIndexedDbInstance(this.logger);\n\t\t}\n\t\tif (this.db === undefined) {\n\t\t\tconst dbInstance = await getFluidCacheIndexedDbInstance(this.logger);\n\t\t\tif (this.db === undefined) {\n\t\t\t\t// Reset the counter on first open.\n\t\t\t\tthis.dbReuseCount = -1;\n\t\t\t\tthis.db = dbInstance;\n\t\t\t} else {\n\t\t\t\tdbInstance.close();\n\t\t\t\tthis.dbReuseCount += 1;\n\t\t\t\treturn this.db;\n\t\t\t}\n\t\t\t// Need to close the db on version change if opened.\n\t\t\tthis.db.onversionchange = (ev) => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t};\n\t\t\tthis.db.addEventListener(\"close\", (ev) => {\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t\tthis.db = undefined;\n\t\t\t});\n\t\t\t// Schedule db close after this.closeDbAfterMs.\n\t\t\tassert(this.dbCloseTimer === undefined, 0x6c6 /* timer should not be set yet!! */);\n\t\t\tthis.dbCloseTimer = setTimeout(() => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t}, this.closeDbAfterMs);\n\t\t}\n\t\tassert(this.db !== undefined, 0x6c7 /* db should be intialized by now */);\n\t\tthis.dbReuseCount += 1;\n\t\treturn this.db;\n\t}\n\n\tprivate closeDb(db?: IDBPDatabase<FluidCacheDBSchema>) {\n\t\tif (this.closeDbImmediately) {\n\t\t\tdb?.close();\n\t\t}\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\tconst index = transaction.store.index(\"fileId\");\n\n\t\t\tconst keysToDelete = await index.getAllKeys(file.docId);\n\n\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\tawait transaction.done;\n\t\t} catch (error: any) {\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n\n\tpublic async get(cacheEntry: ICacheEntry): Promise<any> {\n\t\tconst startTime = performance.now();\n\n\t\tconst cachedItem = await this.getItemFromCache(cacheEntry);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"FluidCacheAccess\",\n\t\t\tcacheHit: cachedItem !== undefined,\n\t\t\ttype: cacheEntry.type,\n\t\t\tduration: performance.now() - startTime,\n\t\t\tdbOpenPerf: cachedItem?.dbOpenPerf,\n\t\t\tdbReuseCount: this.dbReuseCount,\n\t\t\tpkgVersion,\n\t\t});\n\n\t\t// Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn cachedItem?.cachedObject;\n\t}\n\n\tprivate async getItemFromCache(cacheEntry: ICacheEntry) {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst dbOpenStartTime = performance.now();\n\t\t\tdb = await this.openDb();\n\t\t\tconst dbOpenPerf = performance.now() - dbOpenStartTime;\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// If the data does not come from the same partition, don't return it\n\t\t\tif (value.partitionKey !== this.partitionKey) {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\t// If too much time has passed since this cache entry was used, we will also return undefined\n\t\t\tif (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tthis.closeDb(db);\n\t\t\treturn { ...value, dbOpenPerf };\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us. Return undefined in this case\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCacheGetError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\tawait db.put(\n\t\t\t\tFluidDriverObjectStoreName,\n\t\t\t\t{\n\t\t\t\t\tcachedObject: value,\n\t\t\t\t\tfileId: entry.file.docId,\n\t\t\t\t\ttype: entry.type,\n\t\t\t\t\tcacheItemId: entry.key,\n\t\t\t\t\tpartitionKey: this.partitionKey,\n\t\t\t\t\tcreatedTimeMs: currentTime,\n\t\t\t\t\tlastAccessTimeMs: currentTime,\n\t\t\t\t},\n\t\t\t\tgetKeyForCacheEntry(entry),\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCachePutError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n}\n"]}
@@ -3,7 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { ICacheEntry } from "@fluidframework/odsp-driver-definitions/internal";
7
6
  import { DBSchema, DeleteDBCallbacks, IDBPDatabase } from "idb";
8
7
  export declare const FluidDriverCacheDBName = "fluidDriverCache";
9
8
  export declare const FluidDriverObjectStoreName = "driverStorage.V3";
@@ -11,7 +10,6 @@ export declare const CurrentCacheVersion = 3;
11
10
  export declare const oldVersionNameMapping: Partial<{
12
11
  [key: number]: string;
13
12
  }>;
14
- export declare function getKeyForCacheEntry(entry: ICacheEntry): string;
15
13
  export declare function getFluidCacheIndexedDbInstance(logger?: ITelemetryBaseLogger): Promise<IDBPDatabase<FluidCacheDBSchema>>;
16
14
  /**
17
15
  * Deletes the indexed DB instance.
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.d.ts","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,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AC;SACzB,CAAC;QAEF,OAAO,EAAE;YACR,aAAa,EAAE,MAAM,CAAC;YACtB,YAAY,EAAE,MAAM,CAAC;YACrB,gBAAgB,EAAE,MAAM,CAAC;YACzB,MAAM,EAAE,MAAM,CAAC;SACf,CAAC;KACF,CAAC;CACF"}
@@ -4,9 +4,8 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.deleteFluidCacheIndexDbInstance = exports.getFluidCacheIndexedDbInstance = exports.getKeyForCacheEntry = exports.oldVersionNameMapping = exports.CurrentCacheVersion = exports.FluidDriverObjectStoreName = exports.FluidDriverCacheDBName = void 0;
8
- const internal_1 = require("@fluidframework/odsp-driver-definitions/internal");
9
- const internal_2 = require("@fluidframework/telemetry-utils/internal");
7
+ exports.deleteFluidCacheIndexDbInstance = exports.getFluidCacheIndexedDbInstance = exports.oldVersionNameMapping = exports.CurrentCacheVersion = exports.FluidDriverObjectStoreName = exports.FluidDriverCacheDBName = void 0;
8
+ const internal_1 = require("@fluidframework/telemetry-utils/internal");
10
9
  const idb_1 = require("idb");
11
10
  // The name of the database that we use for caching Fluid info.
12
11
  exports.FluidDriverCacheDBName = "fluidDriverCache";
@@ -18,10 +17,6 @@ exports.oldVersionNameMapping = {
18
17
  1: "diverStorage",
19
18
  2: "diverStorage.V2",
20
19
  };
21
- function getKeyForCacheEntry(entry) {
22
- return (0, internal_1.getKeyForCacheEntry)(entry);
23
- }
24
- exports.getKeyForCacheEntry = getKeyForCacheEntry;
25
20
  function getFluidCacheIndexedDbInstance(logger) {
26
21
  return new Promise((resolve, reject) => {
27
22
  (0, idb_1.openDB)(exports.FluidDriverCacheDBName, exports.CurrentCacheVersion, {
@@ -40,7 +35,7 @@ function getFluidCacheIndexedDbInstance(logger) {
40
35
  // Catch any error done when attempting to delete the older version.
41
36
  // If the object does not exist db will throw.
42
37
  // We can now assume that the old version is no longer there regardless.
43
- (0, internal_2.createChildLogger)({ logger }).sendErrorEvent({
38
+ (0, internal_1.createChildLogger)({ logger }).sendErrorEvent({
44
39
  eventName: "FluidCacheDeleteOldDbError" /* FluidCacheErrorEvent.FluidCacheDeleteOldDbError */,
45
40
  }, error);
46
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+EAG0D;AAC1D,uEAA6E;AAC7E,6BAAkF;AAIlF,+DAA+D;AAClD,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,+GAA+G;AAClG,QAAA,0BAA0B,GAAG,kBAAkB,CAAC;AAEhD,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC,kGAAkG;AACrF,QAAA,qBAAqB,GAAuC;IACxE,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,iBAAiB;CACpB,CAAC;AAEF,SAAgB,mBAAmB,CAAC,KAAkB;IACrD,OAAO,IAAA,8BAAuB,EAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAFD,kDAEC;AAED,SAAgB,8BAA8B,CAC7C,MAA6B;IAE7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAA,YAAM,EAAqB,8BAAsB,EAAE,2BAAmB,EAAE;YACvE,OAAO,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBACJ,wDAAwD;oBACxD,kDAAkD;oBAClD,MAAM,aAAa,GAAG,6BAAqB,CAAC,UAAU,CAAC,CAAC;oBACxD,IAAI,aAAa,EAAE,CAAC;wBACnB,sEAAsE;wBACtE,sDAAsD;wBACtD,EAAE,CAAC,iBAAiB,CAAC,aAAoB,CAAC,CAAC;oBAC5C,CAAC;gBACF,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACrB,oEAAoE;oBACpE,8CAA8C;oBAC9C,wEAAwE;oBACxE,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC,cAAc,CAC3C;wBACC,SAAS,oFAAiD;qBAC1D,EACD,KAAK,CACL,CAAC;gBACH,CAAC;gBAED,MAAM,gBAAgB,GAAG,EAAE,CAAC,iBAAiB,CAAC,kCAA0B,CAAC,CAAC;gBAC1E,gBAAgB,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;gBAC/D,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;gBACrE,gBAAgB,CAAC,WAAW,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;gBAC7D,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACb,MAAM,CACL,IAAI,KAAK,CACR,+EAA+E,CAC/E,CACD,CAAC;YACH,CAAC;SACD,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACJ,CAAC;AA1CD,wEA0CC;AAED;;;;;GAKG;AACH,SAAgB,+BAA+B,CAC9C,iBAAqC;IAErC,OAAO,IAAA,cAAQ,EAAC,8BAAsB,EAAE,iBAAiB,CAAC,CAAC;AAC5D,CAAC;AAJD,0EAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport {\n\tICacheEntry,\n\tgetKeyForCacheEntry as odspGetKeyForCacheEntry,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport { DBSchema, DeleteDBCallbacks, IDBPDatabase, deleteDB, openDB } from \"idb\";\n\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry.js\";\n\n// The name of the database that we use for caching Fluid info.\nexport const FluidDriverCacheDBName = \"fluidDriverCache\";\n\n// The name of the object store within the indexed db instance that the driver will use to cache Fluid content.\nexport const FluidDriverObjectStoreName = \"driverStorage.V3\";\n\nexport const CurrentCacheVersion = 3;\n\n// Note that V1 and V2 were misspelled as \"diver\", and we need to keep using the misspelling here.\nexport const oldVersionNameMapping: Partial<{ [key: number]: string }> = {\n\t1: \"diverStorage\",\n\t2: \"diverStorage.V2\",\n};\n\nexport function getKeyForCacheEntry(entry: ICacheEntry) {\n\treturn odspGetKeyForCacheEntry(entry);\n}\n\nexport function getFluidCacheIndexedDbInstance(\n\tlogger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n\treturn new Promise((resolve, reject) => {\n\t\topenDB<FluidCacheDBSchema>(FluidDriverCacheDBName, CurrentCacheVersion, {\n\t\t\tupgrade: (db, oldVersion) => {\n\t\t\t\ttry {\n\t\t\t\t\t// We changed the format of the object store, so we must\n\t\t\t\t\t// delete the old stores to create a new one in V3\n\t\t\t\t\tconst cacheToDelete = oldVersionNameMapping[oldVersion];\n\t\t\t\t\tif (cacheToDelete) {\n\t\t\t\t\t\t// We don't include the old object stores in the schema, so we need to\n\t\t\t\t\t\t// use a typecast here to prevent IDB from complaining\n\t\t\t\t\t\tdb.deleteObjectStore(cacheToDelete as any);\n\t\t\t\t\t}\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// Catch any error done when attempting to delete the older version.\n\t\t\t\t\t// If the object does not exist db will throw.\n\t\t\t\t\t// We can now assume that the old version is no longer there regardless.\n\t\t\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst cacheObjectStore = db.createObjectStore(FluidDriverObjectStoreName);\n\t\t\t\tcacheObjectStore.createIndex(\"createdTimeMs\", \"createdTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"lastAccessTimeMs\", \"lastAccessTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"partitionKey\", \"partitionKey\");\n\t\t\t\tcacheObjectStore.createIndex(\"fileId\", \"fileId\");\n\t\t\t},\n\t\t\tblocked: () => {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"Could not open DB since it is blocked by an older client that has the DB open\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t}).then(resolve, reject);\n\t});\n}\n\n/**\n * Deletes the indexed DB instance.\n *\n * @remarks Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\n * @legacy @beta\n */\nexport function deleteFluidCacheIndexDbInstance(\n\tdeleteDBCallbacks?: DeleteDBCallbacks,\n): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName, deleteDBCallbacks);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n\t[FluidDriverObjectStoreName]: {\n\t\t/**\n\t\t * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n\t\t */\n\t\tkey: string;\n\n\t\tvalue: {\n\t\t\t/**\n\t\t\t * The identifier of the file associated with the cache entry\n\t\t\t */\n\t\t\tfileId: string;\n\n\t\t\t/**\n\t\t\t * Describes the type of content being cached, such as snapshot\n\t\t\t */\n\t\t\ttype: string;\n\n\t\t\t/**\n\t\t\t * Files may have multiple cached items associated with them,\n\t\t\t * this property uniquely identifies a specific cache entry for a file.\n\t\t\t * This is not globally unique, but rather a unique id for this file\n\t\t\t */\n\t\t\tcacheItemId: string;\n\n\t\t\t/*\n\t\t\t * Opaque object that the driver asks us to store in a cache for performance reasons\n\t\t\t */\n\t\t\tcachedObject: any;\n\n\t\t\t/**\n\t\t\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t\t\t * Null can be used to explicity indicate no partitioning.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\t\tpartitionKey: string | null;\n\n\t\t\t/**\n\t\t\t * The time when the cache entry was put into the cache\n\t\t\t */\n\t\t\tcreatedTimeMs: number;\n\n\t\t\t/**\n\t\t\t * The last time the cache entry was used.\n\t\t\t * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n\t\t\t * With the recent change, this won't be updated on read as it will not be used anywhere. Only keeping\n\t\t\t * so as to not upgrade the schema version.\n\t\t\t */\n\t\t\tlastAccessTimeMs: number;\n\t\t};\n\n\t\tindexes: {\n\t\t\tcreatedTimeMs: number;\n\t\t\tpartitionKey: string;\n\t\t\tlastAccessTimeMs: number;\n\t\t\tfileId: string;\n\t\t};\n\t};\n}\n"]}
1
+ {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,uEAA6E;AAC7E,6BAAkF;AAIlF,+DAA+D;AAClD,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,+GAA+G;AAClG,QAAA,0BAA0B,GAAG,kBAAkB,CAAC;AAEhD,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC,kGAAkG;AACrF,QAAA,qBAAqB,GAAuC;IACxE,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,iBAAiB;CACpB,CAAC;AAEF,SAAgB,8BAA8B,CAC7C,MAA6B;IAE7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAA,YAAM,EAAqB,8BAAsB,EAAE,2BAAmB,EAAE;YACvE,OAAO,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBACJ,wDAAwD;oBACxD,kDAAkD;oBAClD,MAAM,aAAa,GAAG,6BAAqB,CAAC,UAAU,CAAC,CAAC;oBACxD,IAAI,aAAa,EAAE,CAAC;wBACnB,sEAAsE;wBACtE,sDAAsD;wBACtD,EAAE,CAAC,iBAAiB,CAAC,aAAoB,CAAC,CAAC;oBAC5C,CAAC;gBACF,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACrB,oEAAoE;oBACpE,8CAA8C;oBAC9C,wEAAwE;oBACxE,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC,cAAc,CAC3C;wBACC,SAAS,oFAAiD;qBAC1D,EACD,KAAK,CACL,CAAC;gBACH,CAAC;gBAED,MAAM,gBAAgB,GAAG,EAAE,CAAC,iBAAiB,CAAC,kCAA0B,CAAC,CAAC;gBAC1E,gBAAgB,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;gBAC/D,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;gBACrE,gBAAgB,CAAC,WAAW,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;gBAC7D,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACb,MAAM,CACL,IAAI,KAAK,CACR,+EAA+E,CAC/E,CACD,CAAC;YACH,CAAC;SACD,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACJ,CAAC;AA1CD,wEA0CC;AAED;;;;;GAKG;AACH,SAAgB,+BAA+B,CAC9C,iBAAqC;IAErC,OAAO,IAAA,cAAQ,EAAC,8BAAsB,EAAE,iBAAiB,CAAC,CAAC;AAC5D,CAAC;AAJD,0EAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport { DBSchema, DeleteDBCallbacks, IDBPDatabase, deleteDB, openDB } from \"idb\";\n\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry.js\";\n\n// The name of the database that we use for caching Fluid info.\nexport const FluidDriverCacheDBName = \"fluidDriverCache\";\n\n// The name of the object store within the indexed db instance that the driver will use to cache Fluid content.\nexport const FluidDriverObjectStoreName = \"driverStorage.V3\";\n\nexport const CurrentCacheVersion = 3;\n\n// Note that V1 and V2 were misspelled as \"diver\", and we need to keep using the misspelling here.\nexport const oldVersionNameMapping: Partial<{ [key: number]: string }> = {\n\t1: \"diverStorage\",\n\t2: \"diverStorage.V2\",\n};\n\nexport function getFluidCacheIndexedDbInstance(\n\tlogger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n\treturn new Promise((resolve, reject) => {\n\t\topenDB<FluidCacheDBSchema>(FluidDriverCacheDBName, CurrentCacheVersion, {\n\t\t\tupgrade: (db, oldVersion) => {\n\t\t\t\ttry {\n\t\t\t\t\t// We changed the format of the object store, so we must\n\t\t\t\t\t// delete the old stores to create a new one in V3\n\t\t\t\t\tconst cacheToDelete = oldVersionNameMapping[oldVersion];\n\t\t\t\t\tif (cacheToDelete) {\n\t\t\t\t\t\t// We don't include the old object stores in the schema, so we need to\n\t\t\t\t\t\t// use a typecast here to prevent IDB from complaining\n\t\t\t\t\t\tdb.deleteObjectStore(cacheToDelete as any);\n\t\t\t\t\t}\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// Catch any error done when attempting to delete the older version.\n\t\t\t\t\t// If the object does not exist db will throw.\n\t\t\t\t\t// We can now assume that the old version is no longer there regardless.\n\t\t\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst cacheObjectStore = db.createObjectStore(FluidDriverObjectStoreName);\n\t\t\t\tcacheObjectStore.createIndex(\"createdTimeMs\", \"createdTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"lastAccessTimeMs\", \"lastAccessTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"partitionKey\", \"partitionKey\");\n\t\t\t\tcacheObjectStore.createIndex(\"fileId\", \"fileId\");\n\t\t\t},\n\t\t\tblocked: () => {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"Could not open DB since it is blocked by an older client that has the DB open\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t}).then(resolve, reject);\n\t});\n}\n\n/**\n * Deletes the indexed DB instance.\n *\n * @remarks Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\n * @legacy @beta\n */\nexport function deleteFluidCacheIndexDbInstance(\n\tdeleteDBCallbacks?: DeleteDBCallbacks,\n): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName, deleteDBCallbacks);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n\t[FluidDriverObjectStoreName]: {\n\t\t/**\n\t\t * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n\t\t */\n\t\tkey: string;\n\n\t\tvalue: {\n\t\t\t/**\n\t\t\t * The identifier of the file associated with the cache entry\n\t\t\t */\n\t\t\tfileId: string;\n\n\t\t\t/**\n\t\t\t * Describes the type of content being cached, such as snapshot\n\t\t\t */\n\t\t\ttype: string;\n\n\t\t\t/**\n\t\t\t * Files may have multiple cached items associated with them,\n\t\t\t * this property uniquely identifies a specific cache entry for a file.\n\t\t\t * This is not globally unique, but rather a unique id for this file\n\t\t\t */\n\t\t\tcacheItemId: string;\n\n\t\t\t/*\n\t\t\t * Opaque object that the driver asks us to store in a cache for performance reasons\n\t\t\t */\n\t\t\tcachedObject: any;\n\n\t\t\t/**\n\t\t\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t\t\t * Null can be used to explicity indicate no partitioning.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\t\tpartitionKey: string | null;\n\n\t\t\t/**\n\t\t\t * The time when the cache entry was put into the cache\n\t\t\t */\n\t\t\tcreatedTimeMs: number;\n\n\t\t\t/**\n\t\t\t * The last time the cache entry was used.\n\t\t\t * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n\t\t\t * With the recent change, this won't be updated on read as it will not be used anywhere. Only keeping\n\t\t\t * so as to not upgrade the schema version.\n\t\t\t */\n\t\t\tlastAccessTimeMs: number;\n\t\t};\n\n\t\tindexes: {\n\t\t\tcreatedTimeMs: number;\n\t\t\tpartitionKey: string;\n\t\t\tlastAccessTimeMs: number;\n\t\t\tfileId: string;\n\t\t};\n\t};\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/driver-web-cache";
8
- export declare const pkgVersion = "2.61.0";
8
+ export declare const pkgVersion = "2.62.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/driver-web-cache";
11
- exports.pkgVersion = "2.61.0";
11
+ exports.pkgVersion = "2.62.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,kCAAkC,CAAC;AAC7C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-web-cache\";\nexport const pkgVersion = \"2.61.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,kCAAkC,CAAC;AAC7C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-web-cache\";\nexport const pkgVersion = \"2.62.0\";\n"]}
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { ICacheEntry, IFileEntry, IPersistedCache } from "@fluidframework/odsp-driver-definitions/internal";
6
+ import type { IPersistedCache, IFileEntry, ICacheEntry } from "@fluidframework/driver-definitions/internal";
7
7
  /**
8
8
  * @legacy @beta
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.d.ts","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EACN,WAAW,EACX,UAAU,EACV,eAAe,EAEf,MAAM,kDAAkD,CAAC;AA4B1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;OAMG;IAEH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAE9B;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,UAAW,YAAW,eAAe;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C,OAAO,CAAC,QAAQ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AO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,EAAE,CAA+C;IACzD,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,YAAY,CAAc;gBAEtB,MAAM,EAAE,gBAAgB;YAqFtB,MAAM;IAwCpB,OAAO,CAAC,OAAO;IAMF,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9C,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAoBzC,gBAAgB;IAiDjB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAgC/D"}
package/lib/FluidCache.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
- import { maximumCacheDurationMs, } from "@fluidframework/odsp-driver-definitions/internal";
6
+ import { getKeyForCacheEntry, maximumCacheDurationMs, } from "@fluidframework/driver-utils/internal";
7
7
  import { UsageError, createChildLogger, } from "@fluidframework/telemetry-utils/internal";
8
- import { FluidDriverObjectStoreName, getFluidCacheIndexedDbInstance, getKeyForCacheEntry, } from "./FluidCacheIndexedDb.js";
8
+ import { FluidDriverObjectStoreName, getFluidCacheIndexedDbInstance, } from "./FluidCacheIndexedDb.js";
9
9
  import { pkgVersion } from "./packageVersion.js";
10
10
  import { scheduleIdleTask } from "./scheduleIdleTask.js";
11
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAIN,sBAAsB,GACtB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEN,UAAU,EACV,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EA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AAC,MAAM,EAAE,CAAC;YAEzB,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;YAEzC,MAAM,EAAE,CAAC,GAAG,CACX,0BAA0B,EAC1B;gBACC,YAAY,EAAE,KAAK;gBACnB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;gBACxB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,WAAW,EAAE,KAAK,CAAC,GAAG;gBACtB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,aAAa,EAAE,WAAW;gBAC1B,gBAAgB,EAAE,WAAW;aAC7B,EACD,mBAAmB,CAAC,KAAK,CAAC,CAC1B,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACrB,uDAAuD;YACvD,6DAA6D;YAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CACzB,EAAE,SAAS,oEAAyC,EAAE,UAAU,EAAE,EAClE,KAAK,CACL,CAAC;QACH,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tICacheEntry,\n\tIFileEntry,\n\tIPersistedCache,\n\tmaximumCacheDurationMs,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { IDBPDatabase } from \"idb\";\n\nimport {\n\tFluidCacheDBSchema,\n\tFluidDriverObjectStoreName,\n\tgetFluidCacheIndexedDbInstance,\n\tgetKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb.js\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask.js\";\n\n// Some browsers have a usageDetails property that will tell you more detailed information\n// on how the storage is being used\ninterface StorageQuotaUsageDetails {\n\tindexedDB: number | undefined;\n}\n\n/**\n * @legacy @beta\n */\nexport interface FluidCacheConfig {\n\t/**\n\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t * Null can be used to explicity indicate no partitioning, and has been chosen\n\t * vs undefined so that it is clear this is an intentional choice by the caller.\n\t * A null value should only be used when the host can ensure that the cache is not able\n\t * to be shared with multiple users.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpartitionKey: string | null;\n\n\t/**\n\t * A logger that can be used to get insight into cache performance and errors\n\t */\n\tlogger?: ITelemetryBaseLogger;\n\n\t/**\n\t * A value in milliseconds that determines the maximum age of a cache entry to return.\n\t * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n\t */\n\tmaxCacheItemAge: number;\n\n\t/**\n\t * Each time db is opened, it will remain open for this much time. To improve perf, if this property is set as\n\t * any number greater than 0, then db will not be closed immediately after usage. This value is in milliseconds.\n\t */\n\tcloseDbAfterMs?: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance.\n * @legacy @beta\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\tprivate readonly closeDbImmediately: boolean = true;\n\tprivate readonly closeDbAfterMs: number;\n\tprivate db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\tprivate dbCloseTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate dbReuseCount: number = -1;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tconst { logger, partitionKey, maxCacheItemAge, closeDbAfterMs } = config;\n\t\tthis.logger = createChildLogger({ logger });\n\t\tthis.partitionKey = partitionKey;\n\t\tif (maxCacheItemAge > maximumCacheDurationMs) {\n\t\t\tconst error = new UsageError(\n\t\t\t\t`maxCacheItemAge(${maxCacheItemAge}) cannot be greater than ${maximumCacheDurationMs}`,\n\t\t\t\t{\n\t\t\t\t\tmaxCacheItemAge,\n\t\t\t\t\tmaximumCacheDurationMs,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// go with logging, rather than throwing for now\n\t\t\t// as throwing could break existing usages\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"maxCacheItemAgeTooLarge\",\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t\tthis.maxCacheItemAge = Math.min(maxCacheItemAge, maximumCacheDurationMs);\n\t\tthis.closeDbAfterMs = closeDbAfterMs ?? 0;\n\t\tif (this.closeDbAfterMs > 0) {\n\t\t\tthis.closeDbImmediately = false;\n\t\t}\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Log how much storage space is currently being used by indexed db.\n\t\t\t// NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n\t\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\t\tif (navigator.storage?.estimate) {\n\t\t\t\tconst estimate = await navigator.storage.estimate();\n\n\t\t\t\t// Some browsers have a usageDetails property that will tell you\n\t\t\t\t// more detailed information on how the storage is being used\n\t\t\t\tlet indexedDBSize: number | undefined;\n\t\t\t\tif (\"usageDetails\" in estimate) {\n\t\t\t\t\tindexedDBSize = ((estimate as any).usageDetails as StorageQuotaUsageDetails)\n\t\t\t\t\t\t.indexedDB;\n\t\t\t\t}\n\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tquota: estimate.quota,\n\t\t\t\t\tusage: estimate.usage,\n\t\t\t\t\tindexedDBSize,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tdb = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"createdTimeMs\");\n\t\t\t\t// Get items which were cached before the maxCacheItemAge.\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - this.maxCacheItemAge),\n\t\t\t\t);\n\n\t\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\t\tawait transaction.done;\n\t\t\t} catch (error: any) {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\t\tpkgVersion,\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t} finally {\n\t\t\t\tdb?.close();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async openDb() {\n\t\tif (this.closeDbImmediately) {\n\t\t\treturn getFluidCacheIndexedDbInstance(this.logger);\n\t\t}\n\t\tif (this.db === undefined) {\n\t\t\tconst dbInstance = await getFluidCacheIndexedDbInstance(this.logger);\n\t\t\tif (this.db === undefined) {\n\t\t\t\t// Reset the counter on first open.\n\t\t\t\tthis.dbReuseCount = -1;\n\t\t\t\tthis.db = dbInstance;\n\t\t\t} else {\n\t\t\t\tdbInstance.close();\n\t\t\t\tthis.dbReuseCount += 1;\n\t\t\t\treturn this.db;\n\t\t\t}\n\t\t\t// Need to close the db on version change if opened.\n\t\t\tthis.db.onversionchange = (ev) => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t};\n\t\t\tthis.db.addEventListener(\"close\", (ev) => {\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t\tthis.db = undefined;\n\t\t\t});\n\t\t\t// Schedule db close after this.closeDbAfterMs.\n\t\t\tassert(this.dbCloseTimer === undefined, 0x6c6 /* timer should not be set yet!! */);\n\t\t\tthis.dbCloseTimer = setTimeout(() => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t}, this.closeDbAfterMs);\n\t\t}\n\t\tassert(this.db !== undefined, 0x6c7 /* db should be intialized by now */);\n\t\tthis.dbReuseCount += 1;\n\t\treturn this.db;\n\t}\n\n\tprivate closeDb(db?: IDBPDatabase<FluidCacheDBSchema>) {\n\t\tif (this.closeDbImmediately) {\n\t\t\tdb?.close();\n\t\t}\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\tconst index = transaction.store.index(\"fileId\");\n\n\t\t\tconst keysToDelete = await index.getAllKeys(file.docId);\n\n\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\tawait transaction.done;\n\t\t} catch (error: any) {\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n\n\tpublic async get(cacheEntry: ICacheEntry): Promise<any> {\n\t\tconst startTime = performance.now();\n\n\t\tconst cachedItem = await this.getItemFromCache(cacheEntry);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"FluidCacheAccess\",\n\t\t\tcacheHit: cachedItem !== undefined,\n\t\t\ttype: cacheEntry.type,\n\t\t\tduration: performance.now() - startTime,\n\t\t\tdbOpenPerf: cachedItem?.dbOpenPerf,\n\t\t\tdbReuseCount: this.dbReuseCount,\n\t\t\tpkgVersion,\n\t\t});\n\n\t\t// Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn cachedItem?.cachedObject;\n\t}\n\n\tprivate async getItemFromCache(cacheEntry: ICacheEntry) {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst dbOpenStartTime = performance.now();\n\t\t\tdb = await this.openDb();\n\t\t\tconst dbOpenPerf = performance.now() - dbOpenStartTime;\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// If the data does not come from the same partition, don't return it\n\t\t\tif (value.partitionKey !== this.partitionKey) {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\t// If too much time has passed since this cache entry was used, we will also return undefined\n\t\t\tif (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tthis.closeDb(db);\n\t\t\treturn { ...value, dbOpenPerf };\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us. Return undefined in this case\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCacheGetError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\tawait db.put(\n\t\t\t\tFluidDriverObjectStoreName,\n\t\t\t\t{\n\t\t\t\t\tcachedObject: value,\n\t\t\t\t\tfileId: entry.file.docId,\n\t\t\t\t\ttype: entry.type,\n\t\t\t\t\tcacheItemId: entry.key,\n\t\t\t\t\tpartitionKey: this.partitionKey,\n\t\t\t\t\tcreatedTimeMs: currentTime,\n\t\t\t\t\tlastAccessTimeMs: currentTime,\n\t\t\t\t},\n\t\t\t\tgetKeyForCacheEntry(entry),\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCachePutError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,E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AAS,CAAC;QAClB,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,KAAkB,EAAE,KAAU;QAC9C,IAAI,EAAgD,CAAC;QACrD,IAAI,CAAC;YACJ,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YAEzB,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;YAEzC,MAAM,EAAE,CAAC,GAAG,CACX,0BAA0B,EAC1B;gBACC,YAAY,EAAE,KAAK;gBACnB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;gBACxB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,WAAW,EAAE,KAAK,CAAC,GAAG;gBACtB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,aAAa,EAAE,WAAW;gBAC1B,gBAAgB,EAAE,WAAW;aAC7B,EACD,mBAAmB,CAAC,KAAK,CAAC,CAC1B,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACrB,uDAAuD;YACvD,6DAA6D;YAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CACzB,EAAE,SAAS,oEAAyC,EAAE,UAAU,EAAE,EAClE,KAAK,CACL,CAAC;QACH,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIPersistedCache,\n\tIFileEntry,\n\tICacheEntry,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tgetKeyForCacheEntry,\n\tmaximumCacheDurationMs,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { IDBPDatabase } from \"idb\";\n\nimport {\n\tFluidCacheDBSchema,\n\tFluidDriverObjectStoreName,\n\tgetFluidCacheIndexedDbInstance,\n} from \"./FluidCacheIndexedDb.js\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask.js\";\n\n// Some browsers have a usageDetails property that will tell you more detailed information\n// on how the storage is being used\ninterface StorageQuotaUsageDetails {\n\tindexedDB: number | undefined;\n}\n\n/**\n * @legacy @beta\n */\nexport interface FluidCacheConfig {\n\t/**\n\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t * Null can be used to explicity indicate no partitioning, and has been chosen\n\t * vs undefined so that it is clear this is an intentional choice by the caller.\n\t * A null value should only be used when the host can ensure that the cache is not able\n\t * to be shared with multiple users.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpartitionKey: string | null;\n\n\t/**\n\t * A logger that can be used to get insight into cache performance and errors\n\t */\n\tlogger?: ITelemetryBaseLogger;\n\n\t/**\n\t * A value in milliseconds that determines the maximum age of a cache entry to return.\n\t * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n\t */\n\tmaxCacheItemAge: number;\n\n\t/**\n\t * Each time db is opened, it will remain open for this much time. To improve perf, if this property is set as\n\t * any number greater than 0, then db will not be closed immediately after usage. This value is in milliseconds.\n\t */\n\tcloseDbAfterMs?: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance.\n * @legacy @beta\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\tprivate readonly closeDbImmediately: boolean = true;\n\tprivate readonly closeDbAfterMs: number;\n\tprivate db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\tprivate dbCloseTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate dbReuseCount: number = -1;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tconst { logger, partitionKey, maxCacheItemAge, closeDbAfterMs } = config;\n\t\tthis.logger = createChildLogger({ logger });\n\t\tthis.partitionKey = partitionKey;\n\t\tif (maxCacheItemAge > maximumCacheDurationMs) {\n\t\t\tconst error = new UsageError(\n\t\t\t\t`maxCacheItemAge(${maxCacheItemAge}) cannot be greater than ${maximumCacheDurationMs}`,\n\t\t\t\t{\n\t\t\t\t\tmaxCacheItemAge,\n\t\t\t\t\tmaximumCacheDurationMs,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// go with logging, rather than throwing for now\n\t\t\t// as throwing could break existing usages\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"maxCacheItemAgeTooLarge\",\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t\tthis.maxCacheItemAge = Math.min(maxCacheItemAge, maximumCacheDurationMs);\n\t\tthis.closeDbAfterMs = closeDbAfterMs ?? 0;\n\t\tif (this.closeDbAfterMs > 0) {\n\t\t\tthis.closeDbImmediately = false;\n\t\t}\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Log how much storage space is currently being used by indexed db.\n\t\t\t// NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n\t\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\t\tif (navigator.storage?.estimate) {\n\t\t\t\tconst estimate = await navigator.storage.estimate();\n\n\t\t\t\t// Some browsers have a usageDetails property that will tell you\n\t\t\t\t// more detailed information on how the storage is being used\n\t\t\t\tlet indexedDBSize: number | undefined;\n\t\t\t\tif (\"usageDetails\" in estimate) {\n\t\t\t\t\tindexedDBSize = ((estimate as any).usageDetails as StorageQuotaUsageDetails)\n\t\t\t\t\t\t.indexedDB;\n\t\t\t\t}\n\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tquota: estimate.quota,\n\t\t\t\t\tusage: estimate.usage,\n\t\t\t\t\tindexedDBSize,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tdb = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"createdTimeMs\");\n\t\t\t\t// Get items which were cached before the maxCacheItemAge.\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - this.maxCacheItemAge),\n\t\t\t\t);\n\n\t\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\t\tawait transaction.done;\n\t\t\t} catch (error: any) {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\t\tpkgVersion,\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t} finally {\n\t\t\t\tdb?.close();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async openDb() {\n\t\tif (this.closeDbImmediately) {\n\t\t\treturn getFluidCacheIndexedDbInstance(this.logger);\n\t\t}\n\t\tif (this.db === undefined) {\n\t\t\tconst dbInstance = await getFluidCacheIndexedDbInstance(this.logger);\n\t\t\tif (this.db === undefined) {\n\t\t\t\t// Reset the counter on first open.\n\t\t\t\tthis.dbReuseCount = -1;\n\t\t\t\tthis.db = dbInstance;\n\t\t\t} else {\n\t\t\t\tdbInstance.close();\n\t\t\t\tthis.dbReuseCount += 1;\n\t\t\t\treturn this.db;\n\t\t\t}\n\t\t\t// Need to close the db on version change if opened.\n\t\t\tthis.db.onversionchange = (ev) => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t};\n\t\t\tthis.db.addEventListener(\"close\", (ev) => {\n\t\t\t\tclearTimeout(this.dbCloseTimer);\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t\tthis.db = undefined;\n\t\t\t});\n\t\t\t// Schedule db close after this.closeDbAfterMs.\n\t\t\tassert(this.dbCloseTimer === undefined, 0x6c6 /* timer should not be set yet!! */);\n\t\t\tthis.dbCloseTimer = setTimeout(() => {\n\t\t\t\tthis.db?.close();\n\t\t\t\tthis.db = undefined;\n\t\t\t\tthis.dbCloseTimer = undefined;\n\t\t\t}, this.closeDbAfterMs);\n\t\t}\n\t\tassert(this.db !== undefined, 0x6c7 /* db should be intialized by now */);\n\t\tthis.dbReuseCount += 1;\n\t\treturn this.db;\n\t}\n\n\tprivate closeDb(db?: IDBPDatabase<FluidCacheDBSchema>) {\n\t\tif (this.closeDbImmediately) {\n\t\t\tdb?.close();\n\t\t}\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\tconst index = transaction.store.index(\"fileId\");\n\n\t\t\tconst keysToDelete = await index.getAllKeys(file.docId);\n\n\t\t\tawait Promise.all(keysToDelete.map((key) => transaction.store.delete(key)));\n\t\t\tawait transaction.done;\n\t\t} catch (error: any) {\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n\n\tpublic async get(cacheEntry: ICacheEntry): Promise<any> {\n\t\tconst startTime = performance.now();\n\n\t\tconst cachedItem = await this.getItemFromCache(cacheEntry);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"FluidCacheAccess\",\n\t\t\tcacheHit: cachedItem !== undefined,\n\t\t\ttype: cacheEntry.type,\n\t\t\tduration: performance.now() - startTime,\n\t\t\tdbOpenPerf: cachedItem?.dbOpenPerf,\n\t\t\tdbReuseCount: this.dbReuseCount,\n\t\t\tpkgVersion,\n\t\t});\n\n\t\t// Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn cachedItem?.cachedObject;\n\t}\n\n\tprivate async getItemFromCache(cacheEntry: ICacheEntry) {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst dbOpenStartTime = performance.now();\n\t\t\tdb = await this.openDb();\n\t\t\tconst dbOpenPerf = performance.now() - dbOpenStartTime;\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// If the data does not come from the same partition, don't return it\n\t\t\tif (value.partitionKey !== this.partitionKey) {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n\t\t\t\t\tsubCategory: FluidCacheEventSubCategories.FluidCache,\n\t\t\t\t\tpkgVersion,\n\t\t\t\t});\n\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\t// If too much time has passed since this cache entry was used, we will also return undefined\n\t\t\tif (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n\t\t\t\tthis.closeDb(db);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tthis.closeDb(db);\n\t\t\treturn { ...value, dbOpenPerf };\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us. Return undefined in this case\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCacheGetError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\tlet db: IDBPDatabase<FluidCacheDBSchema> | undefined;\n\t\ttry {\n\t\t\tdb = await this.openDb();\n\n\t\t\tconst currentTime = new Date().getTime();\n\n\t\t\tawait db.put(\n\t\t\t\tFluidDriverObjectStoreName,\n\t\t\t\t{\n\t\t\t\t\tcachedObject: value,\n\t\t\t\t\tfileId: entry.file.docId,\n\t\t\t\t\ttype: entry.type,\n\t\t\t\t\tcacheItemId: entry.key,\n\t\t\t\t\tpartitionKey: this.partitionKey,\n\t\t\t\t\tcreatedTimeMs: currentTime,\n\t\t\t\t\tlastAccessTimeMs: currentTime,\n\t\t\t\t},\n\t\t\t\tgetKeyForCacheEntry(entry),\n\t\t\t);\n\t\t\tthis.closeDb(db);\n\t\t} catch (error: any) {\n\t\t\t// We can fail to open the db for a variety of reasons,\n\t\t\t// such as the database version having upgraded underneath us\n\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t{ eventName: FluidCacheErrorEvent.FluidCachePutError, pkgVersion },\n\t\t\t\terror,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.closeDb(db);\n\t\t}\n\t}\n}\n"]}
@@ -3,7 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { ICacheEntry } from "@fluidframework/odsp-driver-definitions/internal";
7
6
  import { DBSchema, DeleteDBCallbacks, IDBPDatabase } from "idb";
8
7
  export declare const FluidDriverCacheDBName = "fluidDriverCache";
9
8
  export declare const FluidDriverObjectStoreName = "driverStorage.V3";
@@ -11,7 +10,6 @@ export declare const CurrentCacheVersion = 3;
11
10
  export declare const oldVersionNameMapping: Partial<{
12
11
  [key: number]: string;
13
12
  }>;
14
- export declare function getKeyForCacheEntry(entry: ICacheEntry): string;
15
13
  export declare function getFluidCacheIndexedDbInstance(logger?: ITelemetryBaseLogger): Promise<IDBPDatabase<FluidCacheDBSchema>>;
16
14
  /**
17
15
  * Deletes the indexed DB instance.
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.d.ts","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EACN,WAAW,EAEX,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAoB,MAAM,KAAK,CAAC;AAKlF,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAGzD,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAE7D,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAGrC,eAAO,MAAM,qBAAqB,EAAE,OAAO,CAAC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAGpE,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,UAErD;AAED,wBAAgB,8BAA8B,CAC7C,MAAM,CA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AE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAGpE,CAAC;AAEF,wBAAgB,8BAA8B,CAC7C,MAAM,CAAC,EAAE,oBAAoB,GAC3B,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAwC3C;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC9C,iBAAiB,CAAC,EAAE,iBAAiB,GACnC,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,QAAQ;IACnD,CAAC,0BAA0B,CAAC,EAAE;QAC7B;;WAEG;QACH,GAAG,EAAE,MAAM,CAAC;QAEZ,KAAK,EAAE;YACN;;eAEG;YACH,MAAM,EAAE,MAAM,CAAC;YAEf;;eAEG;YACH,IAAI,EAAE,MAAM,CAAC;YAEb;;;;eAIG;YACH,WAAW,EAAE,MAAM,CAAC;YAKpB,YAAY,EAAE,GAAG,CAAC;YAElB;;;eAGG;YAEH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;YAE5B;;eAEG;YACH,aAAa,EAAE,MAAM,CAAC;YAEtB;;;;;eAKG;YACH,gBAAgB,EAAE,MAAM,CAAC;SACzB,CAAC;QAEF,OAAO,EAAE;YACR,aAAa,EAAE,MAAM,CAAC;YACtB,YAAY,EAAE,MAAM,CAAC;YACrB,gBAAgB,EAAE,MAAM,CAAC;YACzB,MAAM,EAAE,MAAM,CAAC;SACf,CAAC;KACF,CAAC;CACF"}
@@ -2,7 +2,6 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { getKeyForCacheEntry as odspGetKeyForCacheEntry, } from "@fluidframework/odsp-driver-definitions/internal";
6
5
  import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
7
6
  import { deleteDB, openDB } from "idb";
8
7
  // The name of the database that we use for caching Fluid info.
@@ -15,9 +14,6 @@ export const oldVersionNameMapping = {
15
14
  1: "diverStorage",
16
15
  2: "diverStorage.V2",
17
16
  };
18
- export function getKeyForCacheEntry(entry) {
19
- return odspGetKeyForCacheEntry(entry);
20
- }
21
17
  export function getFluidCacheIndexedDbInstance(logger) {
22
18
  return new Promise((resolve, reject) => {
23
19
  openDB(FluidDriverCacheDBName, CurrentCacheVersion, {
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEN,mBAAmB,IAAI,uBAAuB,GAC9C,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAA6C,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAIlF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,+GAA+G;AAC/G,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAE7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,kGAAkG;AAClG,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACxE,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,iBAAiB;CACpB,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,KAAkB;IACrD,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC7C,MAA6B;IAE7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,CAAqB,sBAAsB,EAAE,mBAAmB,EAAE;YACvE,OAAO,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBACJ,wDAAwD;oBACxD,kDAAkD;oBAClD,MAAM,aAAa,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;oBACxD,IAAI,aAAa,EAAE,CAAC;wBACnB,sEAAsE;wBACtE,sDAAsD;wBACtD,EAAE,CAAC,iBAAiB,CAAC,aAAoB,CAAC,CAAC;oBAC5C,CAAC;gBACF,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACrB,oEAAoE;oBACpE,8CAA8C;oBAC9C,wEAAwE;oBACxE,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,cAAc,CAC3C;wBACC,SAAS,oFAAiD;qBAC1D,EACD,KAAK,CACL,CAAC;gBACH,CAAC;gBAED,MAAM,gBAAgB,GAAG,EAAE,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAAC;gBAC1E,gBAAgB,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;gBAC/D,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;gBACrE,gBAAgB,CAAC,WAAW,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;gBAC7D,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACb,MAAM,CACL,IAAI,KAAK,CACR,+EAA+E,CAC/E,CACD,CAAC;YACH,CAAC;SACD,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAC9C,iBAAqC;IAErC,OAAO,QAAQ,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport {\n\tICacheEntry,\n\tgetKeyForCacheEntry as odspGetKeyForCacheEntry,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport { DBSchema, DeleteDBCallbacks, IDBPDatabase, deleteDB, openDB } from \"idb\";\n\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry.js\";\n\n// The name of the database that we use for caching Fluid info.\nexport const FluidDriverCacheDBName = \"fluidDriverCache\";\n\n// The name of the object store within the indexed db instance that the driver will use to cache Fluid content.\nexport const FluidDriverObjectStoreName = \"driverStorage.V3\";\n\nexport const CurrentCacheVersion = 3;\n\n// Note that V1 and V2 were misspelled as \"diver\", and we need to keep using the misspelling here.\nexport const oldVersionNameMapping: Partial<{ [key: number]: string }> = {\n\t1: \"diverStorage\",\n\t2: \"diverStorage.V2\",\n};\n\nexport function getKeyForCacheEntry(entry: ICacheEntry) {\n\treturn odspGetKeyForCacheEntry(entry);\n}\n\nexport function getFluidCacheIndexedDbInstance(\n\tlogger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n\treturn new Promise((resolve, reject) => {\n\t\topenDB<FluidCacheDBSchema>(FluidDriverCacheDBName, CurrentCacheVersion, {\n\t\t\tupgrade: (db, oldVersion) => {\n\t\t\t\ttry {\n\t\t\t\t\t// We changed the format of the object store, so we must\n\t\t\t\t\t// delete the old stores to create a new one in V3\n\t\t\t\t\tconst cacheToDelete = oldVersionNameMapping[oldVersion];\n\t\t\t\t\tif (cacheToDelete) {\n\t\t\t\t\t\t// We don't include the old object stores in the schema, so we need to\n\t\t\t\t\t\t// use a typecast here to prevent IDB from complaining\n\t\t\t\t\t\tdb.deleteObjectStore(cacheToDelete as any);\n\t\t\t\t\t}\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// Catch any error done when attempting to delete the older version.\n\t\t\t\t\t// If the object does not exist db will throw.\n\t\t\t\t\t// We can now assume that the old version is no longer there regardless.\n\t\t\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst cacheObjectStore = db.createObjectStore(FluidDriverObjectStoreName);\n\t\t\t\tcacheObjectStore.createIndex(\"createdTimeMs\", \"createdTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"lastAccessTimeMs\", \"lastAccessTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"partitionKey\", \"partitionKey\");\n\t\t\t\tcacheObjectStore.createIndex(\"fileId\", \"fileId\");\n\t\t\t},\n\t\t\tblocked: () => {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"Could not open DB since it is blocked by an older client that has the DB open\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t}).then(resolve, reject);\n\t});\n}\n\n/**\n * Deletes the indexed DB instance.\n *\n * @remarks Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\n * @legacy @beta\n */\nexport function deleteFluidCacheIndexDbInstance(\n\tdeleteDBCallbacks?: DeleteDBCallbacks,\n): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName, deleteDBCallbacks);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n\t[FluidDriverObjectStoreName]: {\n\t\t/**\n\t\t * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n\t\t */\n\t\tkey: string;\n\n\t\tvalue: {\n\t\t\t/**\n\t\t\t * The identifier of the file associated with the cache entry\n\t\t\t */\n\t\t\tfileId: string;\n\n\t\t\t/**\n\t\t\t * Describes the type of content being cached, such as snapshot\n\t\t\t */\n\t\t\ttype: string;\n\n\t\t\t/**\n\t\t\t * Files may have multiple cached items associated with them,\n\t\t\t * this property uniquely identifies a specific cache entry for a file.\n\t\t\t * This is not globally unique, but rather a unique id for this file\n\t\t\t */\n\t\t\tcacheItemId: string;\n\n\t\t\t/*\n\t\t\t * Opaque object that the driver asks us to store in a cache for performance reasons\n\t\t\t */\n\t\t\tcachedObject: any;\n\n\t\t\t/**\n\t\t\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t\t\t * Null can be used to explicity indicate no partitioning.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\t\tpartitionKey: string | null;\n\n\t\t\t/**\n\t\t\t * The time when the cache entry was put into the cache\n\t\t\t */\n\t\t\tcreatedTimeMs: number;\n\n\t\t\t/**\n\t\t\t * The last time the cache entry was used.\n\t\t\t * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n\t\t\t * With the recent change, this won't be updated on read as it will not be used anywhere. Only keeping\n\t\t\t * so as to not upgrade the schema version.\n\t\t\t */\n\t\t\tlastAccessTimeMs: number;\n\t\t};\n\n\t\tindexes: {\n\t\t\tcreatedTimeMs: number;\n\t\t\tpartitionKey: string;\n\t\t\tlastAccessTimeMs: number;\n\t\t\tfileId: string;\n\t\t};\n\t};\n}\n"]}
1
+ {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAA6C,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAIlF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAEzD,+GAA+G;AAC/G,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAE7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,kGAAkG;AAClG,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACxE,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,iBAAiB;CACpB,CAAC;AAEF,MAAM,UAAU,8BAA8B,CAC7C,MAA6B;IAE7B,OAAO,IAAI,OAAO,CAAC,CAAC,OA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iBAAiB,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\nimport { DBSchema, DeleteDBCallbacks, IDBPDatabase, deleteDB, openDB } from \"idb\";\n\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry.js\";\n\n// The name of the database that we use for caching Fluid info.\nexport const FluidDriverCacheDBName = \"fluidDriverCache\";\n\n// The name of the object store within the indexed db instance that the driver will use to cache Fluid content.\nexport const FluidDriverObjectStoreName = \"driverStorage.V3\";\n\nexport const CurrentCacheVersion = 3;\n\n// Note that V1 and V2 were misspelled as \"diver\", and we need to keep using the misspelling here.\nexport const oldVersionNameMapping: Partial<{ [key: number]: string }> = {\n\t1: \"diverStorage\",\n\t2: \"diverStorage.V2\",\n};\n\nexport function getFluidCacheIndexedDbInstance(\n\tlogger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n\treturn new Promise((resolve, reject) => {\n\t\topenDB<FluidCacheDBSchema>(FluidDriverCacheDBName, CurrentCacheVersion, {\n\t\t\tupgrade: (db, oldVersion) => {\n\t\t\t\ttry {\n\t\t\t\t\t// We changed the format of the object store, so we must\n\t\t\t\t\t// delete the old stores to create a new one in V3\n\t\t\t\t\tconst cacheToDelete = oldVersionNameMapping[oldVersion];\n\t\t\t\t\tif (cacheToDelete) {\n\t\t\t\t\t\t// We don't include the old object stores in the schema, so we need to\n\t\t\t\t\t\t// use a typecast here to prevent IDB from complaining\n\t\t\t\t\t\tdb.deleteObjectStore(cacheToDelete as any);\n\t\t\t\t\t}\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// Catch any error done when attempting to delete the older version.\n\t\t\t\t\t// If the object does not exist db will throw.\n\t\t\t\t\t// We can now assume that the old version is no longer there regardless.\n\t\t\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst cacheObjectStore = db.createObjectStore(FluidDriverObjectStoreName);\n\t\t\t\tcacheObjectStore.createIndex(\"createdTimeMs\", \"createdTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"lastAccessTimeMs\", \"lastAccessTimeMs\");\n\t\t\t\tcacheObjectStore.createIndex(\"partitionKey\", \"partitionKey\");\n\t\t\t\tcacheObjectStore.createIndex(\"fileId\", \"fileId\");\n\t\t\t},\n\t\t\tblocked: () => {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"Could not open DB since it is blocked by an older client that has the DB open\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t}).then(resolve, reject);\n\t});\n}\n\n/**\n * Deletes the indexed DB instance.\n *\n * @remarks Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\n * @legacy @beta\n */\nexport function deleteFluidCacheIndexDbInstance(\n\tdeleteDBCallbacks?: DeleteDBCallbacks,\n): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName, deleteDBCallbacks);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n\t[FluidDriverObjectStoreName]: {\n\t\t/**\n\t\t * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n\t\t */\n\t\tkey: string;\n\n\t\tvalue: {\n\t\t\t/**\n\t\t\t * The identifier of the file associated with the cache entry\n\t\t\t */\n\t\t\tfileId: string;\n\n\t\t\t/**\n\t\t\t * Describes the type of content being cached, such as snapshot\n\t\t\t */\n\t\t\ttype: string;\n\n\t\t\t/**\n\t\t\t * Files may have multiple cached items associated with them,\n\t\t\t * this property uniquely identifies a specific cache entry for a file.\n\t\t\t * This is not globally unique, but rather a unique id for this file\n\t\t\t */\n\t\t\tcacheItemId: string;\n\n\t\t\t/*\n\t\t\t * Opaque object that the driver asks us to store in a cache for performance reasons\n\t\t\t */\n\t\t\tcachedObject: any;\n\n\t\t\t/**\n\t\t\t * A string to specify what partition of the cache you wish to use (e.g. a user id).\n\t\t\t * Null can be used to explicity indicate no partitioning.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\t\tpartitionKey: string | null;\n\n\t\t\t/**\n\t\t\t * The time when the cache entry was put into the cache\n\t\t\t */\n\t\t\tcreatedTimeMs: number;\n\n\t\t\t/**\n\t\t\t * The last time the cache entry was used.\n\t\t\t * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n\t\t\t * With the recent change, this won't be updated on read as it will not be used anywhere. Only keeping\n\t\t\t * so as to not upgrade the schema version.\n\t\t\t */\n\t\t\tlastAccessTimeMs: number;\n\t\t};\n\n\t\tindexes: {\n\t\t\tcreatedTimeMs: number;\n\t\t\tpartitionKey: string;\n\t\t\tlastAccessTimeMs: number;\n\t\t\tfileId: string;\n\t\t};\n\t};\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/driver-web-cache";
8
- export declare const pkgVersion = "2.61.0";
8
+ export declare const pkgVersion = "2.62.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/driver-web-cache";
8
- export const pkgVersion = "2.61.0";
8
+ export const pkgVersion = "2.62.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-web-cache\";\nexport const pkgVersion = \"2.61.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-web-cache\";\nexport const pkgVersion = \"2.62.0\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/driver-web-cache",
3
- "version": "2.61.0",
3
+ "version": "2.62.0",
4
4
  "description": "Implementation of the driver caching API for a web browser",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -47,10 +47,11 @@
47
47
  "main": "lib/index.js",
48
48
  "types": "lib/public.d.ts",
49
49
  "dependencies": {
50
- "@fluidframework/core-interfaces": "~2.61.0",
51
- "@fluidframework/core-utils": "~2.61.0",
52
- "@fluidframework/odsp-driver-definitions": "~2.61.0",
53
- "@fluidframework/telemetry-utils": "~2.61.0",
50
+ "@fluidframework/core-interfaces": "~2.62.0",
51
+ "@fluidframework/core-utils": "~2.62.0",
52
+ "@fluidframework/driver-definitions": "~2.62.0",
53
+ "@fluidframework/driver-utils": "~2.62.0",
54
+ "@fluidframework/telemetry-utils": "~2.62.0",
54
55
  "idb": "^6.1.2"
55
56
  },
56
57
  "devDependencies": {
package/src/FluidCache.ts CHANGED
@@ -5,12 +5,15 @@
5
5
 
6
6
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7
7
  import { assert } from "@fluidframework/core-utils/internal";
8
- import {
9
- ICacheEntry,
10
- IFileEntry,
8
+ import type {
11
9
  IPersistedCache,
10
+ IFileEntry,
11
+ ICacheEntry,
12
+ } from "@fluidframework/driver-definitions/internal";
13
+ import {
14
+ getKeyForCacheEntry,
12
15
  maximumCacheDurationMs,
13
- } from "@fluidframework/odsp-driver-definitions/internal";
16
+ } from "@fluidframework/driver-utils/internal";
14
17
  import {
15
18
  ITelemetryLoggerExt,
16
19
  UsageError,
@@ -22,7 +25,6 @@ import {
22
25
  FluidCacheDBSchema,
23
26
  FluidDriverObjectStoreName,
24
27
  getFluidCacheIndexedDbInstance,
25
- getKeyForCacheEntry,
26
28
  } from "./FluidCacheIndexedDb.js";
27
29
  import {
28
30
  FluidCacheErrorEvent,
@@ -4,10 +4,6 @@
4
4
  */
5
5
 
6
6
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7
- import {
8
- ICacheEntry,
9
- getKeyForCacheEntry as odspGetKeyForCacheEntry,
10
- } from "@fluidframework/odsp-driver-definitions/internal";
11
7
  import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
12
8
  import { DBSchema, DeleteDBCallbacks, IDBPDatabase, deleteDB, openDB } from "idb";
13
9
 
@@ -27,10 +23,6 @@ export const oldVersionNameMapping: Partial<{ [key: number]: string }> = {
27
23
  2: "diverStorage.V2",
28
24
  };
29
25
 
30
- export function getKeyForCacheEntry(entry: ICacheEntry) {
31
- return odspGetKeyForCacheEntry(entry);
32
- }
33
-
34
26
  export function getFluidCacheIndexedDbInstance(
35
27
  logger?: ITelemetryBaseLogger,
36
28
  ): Promise<IDBPDatabase<FluidCacheDBSchema>> {
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/driver-web-cache";
9
- export const pkgVersion = "2.61.0";
9
+ export const pkgVersion = "2.62.0";