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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -4,15 +4,15 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
8
- parserOptions: {
9
- project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
- },
11
- rules: {
12
- "@typescript-eslint/no-non-null-assertion": "off",
13
- "@typescript-eslint/no-use-before-define": "off",
14
- "@typescript-eslint/strict-boolean-expressions": "off",
15
- "@typescript-eslint/promise-function-async": "off",
16
- "@typescript-eslint/no-misused-promises": "off",
17
- },
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
+ },
11
+ rules: {
12
+ "@typescript-eslint/no-non-null-assertion": "off",
13
+ "@typescript-eslint/no-use-before-define": "off",
14
+ "@typescript-eslint/strict-boolean-expressions": "off",
15
+ "@typescript-eslint/promise-function-async": "off",
16
+ "@typescript-eslint/no-misused-promises": "off",
17
+ },
18
18
  };
package/README.md CHANGED
@@ -8,25 +8,25 @@ context.
8
8
  ## Usage
9
9
 
10
10
  ```typescript
11
- import { FluidCache } from '@fluidframework/driver-web-cache';
11
+ import { FluidCache } from "@fluidframework/driver-web-cache";
12
12
 
13
13
  new FluidCache({
14
- partitionKey: userId,
15
- logger,
16
- maxCacheItemAge
17
- })
14
+ partitionKey: userId,
15
+ logger,
16
+ maxCacheItemAge,
17
+ });
18
18
  ```
19
19
 
20
20
  ### Parameters
21
21
 
22
- - `partitionKey` - Used to determine what partition of the cache is being used, and can prevent multiple users on the
23
- same machine from sharing a snapshot cache. If you absolutely know that users will not share the cache,
24
- can also be set to `null`. Currently optional, but is proposed to be required in the next major bump.
25
- The recommendation is to use this key to differentiate users for the cache data.
26
- - `logger` - An optional implementation of the logger contract where diagnostic data can be logged.
27
- - `maxCacheItemAge` - The cache tracks a timestamp with each entry. This flag specifies the maximum age (in milliseconds)
28
- for a cache entry to be used. This flag does not control when cached content is deleted since different scenarios and
29
- applications may have different staleness thresholds for the same data.
22
+ - `partitionKey` - Used to determine what partition of the cache is being used, and can prevent multiple users on the
23
+ same machine from sharing a snapshot cache. If you absolutely know that users will not share the cache,
24
+ can also be set to `null`. Currently optional, but is proposed to be required in the next major bump.
25
+ The recommendation is to use this key to differentiate users for the cache data.
26
+ - `logger` - An optional implementation of the logger contract where diagnostic data can be logged.
27
+ - `maxCacheItemAge` - The cache tracks a timestamp with each entry. This flag specifies the maximum age (in milliseconds)
28
+ for a cache entry to be used. This flag does not control when cached content is deleted since different scenarios and
29
+ applications may have different staleness thresholds for the same data.
30
30
 
31
31
  ## Clearing cache entries
32
32
 
@@ -41,11 +41,10 @@ are on point for ensuring responsible usage of the snapshot caching capability t
41
41
  customer promises, such as clearing out storage when appropriate or disabling snapshot caching under certain circumstances,
42
42
  such as when it is known the user is logged in to a public computer.
43
43
 
44
-
45
44
  ```typescript
46
- import { deleteFluidCacheIndexDbInstance } from '@fluidframework/driver-web-cache';
45
+ import { deleteFluidCacheIndexDbInstance } from "@fluidframework/driver-web-cache";
47
46
 
48
- // We put a catch here because Firefox Incognito will throw an error here. This is why we claim this method is a "best effort", since sometimes the browser won't let us access storage
47
+ // We put a catch here because Firefox Incognito will throw an error here. This is why we claim this method is a "best effort", since sometimes the browser won't let us access storage
49
48
  deleteFluidCacheIndexDbInstance().catch(() => {});
50
49
  ```
51
50
 
@@ -1,4 +1,4 @@
1
1
  {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-report.json"
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "@fluidframework/build-common/api-extractor-common-report.json"
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.d.ts","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,eAAe,EACf,WAAW,EACX,UAAU,EACb,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACH,oBAAoB,EAEvB,MAAM,oCAAoC,CAAC;AAoB5C,MAAM,WAAW,gBAAgB;IAC7B;;;;;;OAMG;IAEH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAE9B;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,eAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAE1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,MAAM,EAAE,gBAAgB;IAiEvB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B9C,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAiBzC,gBAAgB;IAsEjB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CA8BlE"}
1
+ {"version":3,"file":"FluidCache.d.ts","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAoB,MAAM,oCAAoC,CAAC;AAoB5F,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;CACxB;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,eAAe;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAE1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,MAAM,EAAE,gBAAgB;IAuDvB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB9C,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAiBzC,gBAAgB;IAkEjB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CA8B/D"}
@@ -27,8 +27,8 @@ class FluidCache {
27
27
  // more detailed information on how the storage is being used
28
28
  let indexedDBSize;
29
29
  if ("usageDetails" in estimate) {
30
- indexedDBSize = estimate
31
- .usageDetails.indexedDB;
30
+ indexedDBSize = estimate.usageDetails
31
+ .indexedDB;
32
32
  }
33
33
  this.logger.sendTelemetryEvent({
34
34
  eventName: "FluidCacheStorageInfo" /* FluidCacheStorageInfo */,
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAWH,qEAA8D;AAC9D,yDAAsD;AACtD,+DAI+B;AAoC/B;;GAEG;AACH,MAAa,UAAU;IAOnB,YAAY,MAAwB;QAChC,IAAI,CAAC,MAAM,GAAG,6BAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAE9C,IAAA,mCAAgB,EAAC,KAAK,IAAI,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,OAAO,KAAU,EAAE;YACjB,uDAAuD;YACvD,6DAA6D;YAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CACtB,EAAE,SAAS,+CAAyC,EAAE,EACtD,KAAK,CACR,CAAC;SACL;IACL,CAAC;CACJ;AAxND,gCAwNC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IPersistedCache,\n ICacheEntry,\n IFileEntry,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n ITelemetryBaseLogger,\n ITelemetryLogger,\n} from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask\";\nimport {\n getFluidCacheIndexedDbInstance,\n FluidDriverObjectStoreName,\n getKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb\";\nimport {\n FluidCacheErrorEvent,\n FluidCacheEventSubCategories,\n FluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry\";\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 indexedDB: number | undefined;\n}\n\nexport interface FluidCacheConfig {\n /**\n * A string to specify what partition of the cache you wish to use (e.g. a user id).\n * Null can be used to explicity indicate no partitioning, and has been chosen\n * vs undefined so that it is clear this is an intentional choice by the caller.\n * A null value should only be used when the host can ensure that the cache is not able\n * to be shared with multiple users.\n */\n // eslint-disable-next-line @rushstack/no-new-null\n partitionKey: string | null;\n\n /**\n * A logger that can be used to get insight into cache performance and errors\n */\n logger?: ITelemetryBaseLogger;\n\n /**\n * A value in milliseconds that determines the maximum age of a cache entry to return.\n * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n */\n maxCacheItemAge: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance\n */\nexport class FluidCache implements IPersistedCache {\n private readonly logger: ITelemetryLogger;\n\n private readonly partitionKey: string | null;\n\n private readonly maxCacheItemAge: number;\n\n constructor(config: FluidCacheConfig) {\n this.logger = ChildLogger.create(config.logger);\n this.partitionKey = config.partitionKey;\n this.maxCacheItemAge = config.maxCacheItemAge;\n\n scheduleIdleTask(async () => {\n // Log how much storage space is currently being used by indexed db.\n // NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n // Exception added when eslint rule was added, this should be revisited when modifying this code\n if (navigator.storage?.estimate) {\n const estimate = await navigator.storage.estimate();\n\n // Some browsers have a usageDetails property that will tell you\n // more detailed information on how the storage is being used\n let indexedDBSize: number | undefined;\n if (\"usageDetails\" in estimate) {\n indexedDBSize = (\n (estimate as any)\n .usageDetails as StorageQuotaUsageDetails\n ).indexedDB;\n }\n\n this.logger.sendTelemetryEvent({\n eventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n subCategory: FluidCacheEventSubCategories.FluidCache,\n quota: estimate.quota,\n usage: estimate.usage,\n indexedDBSize,\n });\n }\n });\n\n scheduleIdleTask(async () => {\n // Delete entries that have not been accessed recently to clean up space\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n const index = transaction.store.index(\"lastAccessTimeMs\");\n // Get items that have not been accessed in 4 weeks\n const keysToDelete = await index.getAllKeys(\n IDBKeyRange.upperBound(\n new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000,\n ),\n );\n\n await Promise.all(\n keysToDelete.map((key) => transaction.store.delete(key)),\n );\n await transaction.done;\n } catch (error: any) {\n this.logger.sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n },\n error,\n );\n }\n });\n }\n\n public async removeEntries(file: IFileEntry): Promise<void> {\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n const index = transaction.store.index(\"fileId\");\n\n const keysToDelete = await index.getAllKeys(file.docId);\n\n await Promise.all(\n keysToDelete.map((key) => transaction.store.delete(key)),\n );\n await transaction.done;\n } catch (error: any) {\n this.logger.sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n },\n error,\n );\n }\n }\n\n public async get(cacheEntry: ICacheEntry): Promise<any> {\n const startTime = performance.now();\n\n const cachedItem = await this.getItemFromCache(cacheEntry);\n\n this.logger.sendPerformanceEvent({\n eventName: \"FluidCacheAccess\",\n cacheHit: cachedItem !== undefined,\n type: cacheEntry.type,\n duration: performance.now() - startTime,\n });\n\n // Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return cachedItem?.cachedObject;\n }\n\n private async getItemFromCache(cacheEntry: ICacheEntry) {\n try {\n const key = getKeyForCacheEntry(cacheEntry);\n\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const value = await db.get(FluidDriverObjectStoreName, key);\n\n if (!value) {\n return undefined;\n }\n\n // If the data does not come from the same partition, don't return it\n if (value.partitionKey !== this.partitionKey) {\n this.logger.sendTelemetryEvent({\n eventName:\n FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n subCategory: FluidCacheEventSubCategories.FluidCache,\n });\n\n return undefined;\n }\n\n const currentTime = new Date().getTime();\n\n // If too much time has passed since this cache entry was used, we will also return undefined\n if (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n return undefined;\n }\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n // We don't want to block the get return of this function on updating the last accessed time\n // We catch this promise because there is no user bad if this is rejected.\n transaction.store\n .get(key)\n .then(async (valueToUpdate) => {\n // This value in the database could have been updated concurrently by other tabs/iframes\n // since we first read it. Only update the last accessed time if the current value in the\n // DB was the same one we returned.\n if (\n valueToUpdate !== undefined &&\n valueToUpdate.createdTimeMs === value.createdTimeMs &&\n (valueToUpdate.lastAccessTimeMs === undefined ||\n valueToUpdate.lastAccessTimeMs < currentTime)\n ) {\n await transaction.store.put(\n { ...valueToUpdate, lastAccessTimeMs: currentTime },\n key,\n );\n }\n await transaction.done;\n\n db.close();\n })\n .catch(() => { });\n return value;\n } catch (error: any) {\n // We can fail to open the db for a variety of reasons,\n // such as the database version having upgraded underneath us. Return undefined in this case\n this.logger.sendErrorEvent(\n { eventName: FluidCacheErrorEvent.FluidCacheGetError },\n error,\n );\n return undefined;\n }\n }\n\n public async put(entry: ICacheEntry, value: any): Promise<void> {\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const currentTime = new Date().getTime();\n\n await db.put(\n FluidDriverObjectStoreName,\n {\n cachedObject: value,\n fileId: entry.file.docId,\n type: entry.type,\n cacheItemId: entry.key,\n partitionKey: this.partitionKey,\n createdTimeMs: currentTime,\n lastAccessTimeMs: currentTime,\n },\n getKeyForCacheEntry(entry),\n );\n\n db.close();\n } catch (error: any) {\n // We can fail to open the db for a variety of reasons,\n // such as the database version having upgraded underneath us\n this.logger.sendErrorEvent(\n { eventName: FluidCacheErrorEvent.FluidCachePutError },\n error,\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,qEAA8D;AAC9D,yDAAsD;AACtD,+DAI+B;AAoC/B;;GAEG;AACH,MAAa,UAAU;IAOtB,YAAY,MAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,6BAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAE9C,IAAA,mCAAgB,EAAC,KAAK,IAAI,EAAE;;YAC3B,oEAAoE;YACpE,wGAAwG;YACxG,gGAAgG;YAChG,IAAI,MAAA,SAAS,CAAC,OAAO,0CAAE,QAAQ,EAAE;gBAChC,MAAM,QAAQ,GAAG,MAA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tD,KAAK,CACL,CAAC;SACF;IACF,CAAC;CACD;AApMD,gCAoMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IPersistedCache, ICacheEntry, IFileEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask\";\nimport {\n\tgetFluidCacheIndexedDbInstance,\n\tFluidDriverObjectStoreName,\n\tgetKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry\";\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\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\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLogger;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tthis.logger = ChildLogger.create(config.logger);\n\t\tthis.partitionKey = config.partitionKey;\n\t\tthis.maxCacheItemAge = config.maxCacheItemAge;\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});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"lastAccessTimeMs\");\n\t\t\t\t// Get items that have not been accessed in 4 weeks\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000),\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},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\ttry {\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\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},\n\t\t\t\terror,\n\t\t\t);\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});\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\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\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});\n\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\treturn undefined;\n\t\t\t}\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t// We don't want to block the get return of this function on updating the last accessed time\n\t\t\t// We catch this promise because there is no user bad if this is rejected.\n\t\t\ttransaction.store\n\t\t\t\t.get(key)\n\t\t\t\t.then(async (valueToUpdate) => {\n\t\t\t\t\t// This value in the database could have been updated concurrently by other tabs/iframes\n\t\t\t\t\t// since we first read it. Only update the last accessed time if the current value in the\n\t\t\t\t\t// DB was the same one we returned.\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalueToUpdate !== undefined &&\n\t\t\t\t\t\tvalueToUpdate.createdTimeMs === value.createdTimeMs &&\n\t\t\t\t\t\t(valueToUpdate.lastAccessTimeMs === undefined ||\n\t\t\t\t\t\t\tvalueToUpdate.lastAccessTimeMs < currentTime)\n\t\t\t\t\t) {\n\t\t\t\t\t\tawait transaction.store.put(\n\t\t\t\t\t\t\t{ ...valueToUpdate, lastAccessTimeMs: currentTime },\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.done;\n\n\t\t\t\t\tdb.close();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t\treturn value;\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 },\n\t\t\t\terror,\n\t\t\t);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\ttry {\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\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\n\t\t\tdb.close();\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 },\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.d.ts","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,QAAQ,EAAE,YAAY,EAAY,MAAM,KAAK,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAK1E,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,C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ACF,gBAAgB,CAAC,WAAW,CACxB,cAAc,EACd,cAAc,CACjB,CAAC;gBACF,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACV,MAAM,CACF,IAAI,KAAK,CACL,+EAA+E,CAClF,CACJ,CAAC;YACN,CAAC;SACJ,CACJ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC;AA1DD,wEA0DC;AAED,mCAAmC;AACnC,+FAA+F;AAC/F,SAAgB,+BAA+B;IAC3C,OAAO,IAAA,cAAQ,EAAC,8BAAsB,CAAC,CAAC;AAC5C,CAAC;AAFD,0EAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { openDB, DBSchema, IDBPDatabase, deleteDB } from \"idb\";\nimport { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry\";\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 1: \"diverStorage\",\n 2: \"diverStorage.V2\",\n};\n\nexport function getKeyForCacheEntry(entry: ICacheEntry) {\n return `${entry.file.docId}_${entry.type}_${entry.key}`;\n}\n\nexport function getFluidCacheIndexedDbInstance(\n logger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n return new Promise((resolve, reject) => {\n openDB<FluidCacheDBSchema>(\n FluidDriverCacheDBName,\n CurrentCacheVersion,\n {\n upgrade: (db, oldVersion) => {\n try {\n // We changed the format of the object store, so we must\n // delete the old stores to create a new one in V3\n const cacheToDelete = oldVersionNameMapping[oldVersion];\n if (cacheToDelete) {\n // We don't include the old object stores in the schema, so we need to\n // use a typecast here to prevent IDB from complaining\n db.deleteObjectStore(cacheToDelete as any);\n }\n } catch (error: any) {\n // Catch any error done when attempting to delete the older version.\n // If the object does not exist db will throw.\n // We can now assume that the old version is no longer there regardless.\n ChildLogger.create(logger).sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n },\n error,\n );\n }\n\n const cacheObjectStore = db.createObjectStore(\n FluidDriverObjectStoreName,\n );\n cacheObjectStore.createIndex(\n \"createdTimeMs\",\n \"createdTimeMs\",\n );\n cacheObjectStore.createIndex(\n \"lastAccessTimeMs\",\n \"lastAccessTimeMs\",\n );\n cacheObjectStore.createIndex(\n \"partitionKey\",\n \"partitionKey\",\n );\n cacheObjectStore.createIndex(\"fileId\", \"fileId\");\n },\n blocked: () => {\n reject(\n new Error(\n \"Could not open DB since it is blocked by an older client that has the DB open\",\n ),\n );\n },\n },\n ).then(resolve, reject);\n });\n}\n\n// Deletes the indexed DB instance.\n// Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\nexport function deleteFluidCacheIndexDbInstance(): Promise<void> {\n return deleteDB(FluidDriverCacheDBName);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n [FluidDriverObjectStoreName]: {\n /**\n * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n */\n key: string;\n\n value: {\n /**\n * The identifier of the file associated with the cache entry\n */\n fileId: string;\n\n /**\n * Describes the type of content being cached, such as snapshot\n */\n type: string;\n\n /**\n * Files may have multiple cached items associated with them,\n * this property uniquely identifies a specific cache entry for a file.\n * This is not globally unique, but rather a unique id for this file\n */\n cacheItemId: string;\n\n /*\n * Opaque object that the driver asks us to store in a cache for performance reasons\n */\n cachedObject: any;\n\n /**\n * A string to specify what partition of the cache you wish to use (e.g. a user id).\n * Null can be used to explicity indicate no partitioning.\n */\n // eslint-disable-next-line @rushstack/no-new-null\n partitionKey: string | null;\n\n /**\n * The time when the cache entry was put into the cache\n */\n createdTimeMs: number;\n\n /**\n * The last time the cache entry was used.\n * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n */\n lastAccessTimeMs: number;\n };\n\n indexes: {\n createdTimeMs: number;\n partitionKey: string;\n lastAccessTimeMs: number;\n fileId: string;\n };\n };\n}\n"]}
1
+ {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA+D;AAG/D,qEAA8D;AAG9D,+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,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;AACzD,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;oBACH,wDAAwD;oBACxD,kDAAkD;oBAClD,MAAM,aAAa,GAAG,6BAAqB,CAAC,UAAU,CAAC,CAAC;oBACxD,IAAI,aAAa,EAAE;wBAClB,sEAAsE;wBACtE,sDAAsD;wBACtD,EAAE,CAAC,iBAAiB,CAAC,aAAoB,CAAC,CAAC;qBAC3C;iBACD;gBAAC,OAAO,KAAU,EAAE;oBACpB,oEAAoE;oBACpE,8CAA8C;oBAC9C,wEAAwE;oBACxE,6BAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CACxC;wBACC,SAAS,+DAAiD;qBAC1D,EACD,KAAK,CACL,CAAC;iBACF;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,mCAAmC;AACnC,+FAA+F;AAC/F,SAAgB,+BAA+B;IAC9C,OAAO,IAAA,cAAQ,EAAC,8BAAsB,CAAC,CAAC;AACzC,CAAC;AAFD,0EAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { openDB, DBSchema, IDBPDatabase, deleteDB } from \"idb\";\nimport { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry\";\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 `${entry.file.docId}_${entry.type}_${entry.key}`;\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\tChildLogger.create(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// Deletes the indexed DB instance.\n// Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\nexport function deleteFluidCacheIndexDbInstance(): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName);\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 */\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 +1 @@
1
- {"version":3,"file":"fluidCacheTelemetry.d.ts","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,sBAAsB;IACpC,uBAAuB,0BAA0B;IACjD,gCAAgC,mCAAmC;CACtE;AAED,0BAAkB,oBAAoB;IAClC,iCAAiC,oCAAoC;IACrE,oBAAoB,uBAAuB;IAC3C,oBAAoB,uBAAuB;IAC3C,4BAA4B,+BAA+B;IAC3D,4BAA4B,+BAA+B;CAC9D;AAED,0BAAkB,4BAA4B;IAC1C,YAAY,eAAe;CAC9B"}
1
+ {"version":3,"file":"fluidCacheTelemetry.d.ts","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,sBAAsB;IACvC,uBAAuB,0BAA0B;IACjD,gCAAgC,mCAAmC;CACnE;AAED,0BAAkB,oBAAoB;IACrC,iCAAiC,oCAAoC;IACrE,oBAAoB,uBAAuB;IAC3C,oBAAoB,uBAAuB;IAC3C,4BAA4B,+BAA+B;IAC3D,4BAA4B,+BAA+B;CAC3D;AAED,0BAAkB,4BAA4B;IAC7C,YAAY,eAAe;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"fluidCacheTelemetry.js","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum FluidCacheGenericEvent {\n \"FluidCacheStorageInfo\" = \"FluidCacheStorageInfo\",\n \"FluidCachePartitionKeyMismatch\" = \"FluidCachePartitionKeyMismatch\",\n}\n\nexport const enum FluidCacheErrorEvent {\n \"FluidCacheDeleteOldEntriesError\" = \"FluidCacheDeleteOldEntriesError\",\n \"FluidCacheGetError\" = \"FluidCacheGetError\",\n \"FluidCachePutError\" = \"FluidCachePutError\",\n \"FluidCacheUpdateUsageError\" = \"FluidCacheUpdateUsageError\",\n \"FluidCacheDeleteOldDbError\" = \"FluidCacheDeleteOldDbError\",\n}\n\nexport const enum FluidCacheEventSubCategories {\n \"FluidCache\" = \"FluidCache\",\n}\n"]}
1
+ {"version":3,"file":"fluidCacheTelemetry.js","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum FluidCacheGenericEvent {\n\t\"FluidCacheStorageInfo\" = \"FluidCacheStorageInfo\",\n\t\"FluidCachePartitionKeyMismatch\" = \"FluidCachePartitionKeyMismatch\",\n}\n\nexport const enum FluidCacheErrorEvent {\n\t\"FluidCacheDeleteOldEntriesError\" = \"FluidCacheDeleteOldEntriesError\",\n\t\"FluidCacheGetError\" = \"FluidCacheGetError\",\n\t\"FluidCachePutError\" = \"FluidCachePutError\",\n\t\"FluidCacheUpdateUsageError\" = \"FluidCacheUpdateUsageError\",\n\t\"FluidCacheDeleteOldDbError\" = \"FluidCacheDeleteOldDbError\",\n}\n\nexport const enum FluidCacheEventSubCategories {\n\t\"FluidCache\" = \"FluidCache\",\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.0.0-internal.3.0.2";
8
+ export declare const pkgVersion = "2.0.0-internal.3.2.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.0.0-internal.3.0.2";
11
+ exports.pkgVersion = "2.0.0-internal.3.2.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,sBAAsB,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.0.0-internal.3.0.2\";\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,sBAAsB,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.0.0-internal.3.2.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3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AAC,KAAK,CAAC,CAAC,CAAC;YAC7C,MAAM;SACT;QAED,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YAClC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACpC;aAAM;YACH,aAAa,CAAC,IAAI,EAAE,CAAC;SACxB;KACJ;IAED,SAAS,GAAG,YAAY,CAAC;AAC7B,CAAC;AAED,uCAAuC;AACvC,SAAS,gBAAgB,CAAC,QAGzB;IACG,wEAAwE;IACxE,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,CAAC;IAClE,iBAAiB,GAAG,KAAK,CAAC;IAE1B,4EAA4E;IAC5E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACtB,kBAAkB,EAAE,CAAC;KACxB;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\ninterface TaskQueueItem {\n /** The task to run */\n task: () => void;\n}\n\n// A set of tasks that still have to be run\nlet taskQueue: TaskQueueItem[] = [];\n\n// Set to true when we have a pending idle task scheduled\nlet idleTaskScheduled = false;\n\n/**\n * A function that schedules a non critical task to be run when the browser has cycles available\n * @param task - The task to be executed\n * @param options - Optional configuration for the task execution\n */\nexport function scheduleIdleTask(task: () => void) {\n taskQueue.push({\n task,\n });\n\n ensureIdleCallback();\n}\n\n/**\n * Ensures an idle callback has been scheduled for the remaining tasks\n */\nfunction ensureIdleCallback() {\n if (!idleTaskScheduled) {\n // Exception added when eslint rule was added, this should be revisited when modifying this code\n if (window.requestIdleCallback) {\n window.requestIdleCallback(idleTaskCallback);\n } else {\n const deadline = Date.now() + 50;\n window.setTimeout(\n () =>\n idleTaskCallback({\n timeRemaining: () => Math.max(deadline - Date.now(), 0),\n didTimeout: false,\n }),\n 0,\n );\n }\n idleTaskScheduled = true;\n }\n}\n\n/**\n * Runs tasks from the task queue\n * @param filter - An optional function that will be called for each task to see if it should run.\n * Returns false for tasks that should not run. If omitted all tasks run.\n * @param shouldContinueRunning - An optional function that will be called to determine if\n * we have enough time to continue running tasks. If omitted, we don't stop running tasks.\n */\nfunction runTasks(\n filter?: (taskQueueItem: TaskQueueItem) => boolean,\n shouldContinueRunning?: () => boolean,\n) {\n // The next value for the task queue\n const newTaskQueue: TaskQueueItem[] = [];\n\n for (let index = 0; index < taskQueue.length; index += 1) {\n if (shouldContinueRunning && !shouldContinueRunning()) {\n // Add the tasks we didn't get to to the end of the new task queue\n newTaskQueue.push(...taskQueue.slice(index));\n break;\n }\n\n const taskQueueItem = taskQueue[index];\n\n if (filter && !filter(taskQueueItem)) {\n newTaskQueue.push(taskQueueItem);\n } else {\n taskQueueItem.task();\n }\n }\n\n taskQueue = newTaskQueue;\n}\n\n// Runs all the tasks in the task queue\nfunction idleTaskCallback(deadline: {\n timeRemaining: () => number;\n readonly didTimeout: boolean;\n}) {\n // Minimum time that must be available on deadline to run any more tasks\n const minTaskTime = 10;\n runTasks(undefined, () => deadline.timeRemaining() > minTaskTime);\n idleTaskScheduled = false;\n\n // If we didn't run through the entire queue, schedule another idle callback\n if (taskQueue.length > 0) {\n ensureIdleCallback();\n }\n}\n"]}
1
+ {"version":3,"file":"scheduleIdleTask.js","sourceRoot":"","sources":["../src/scheduleIdleTask.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,2CAA2C;AAC3C,IAAI,SAAS,GAAoB,EAAE,CAAC;AAEpC,yDAAyD;AACzD,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAgB;IAChD,SAAS,CAAC,IAAI,CAAC;QACd,IAAI;KACJ,CAAC,CAAC;IAEH,kBAAkB,EAAE,CAAC;AACtB,CAAC;AAND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B,CAAC,QAAuE;IAChG,wEAAwE;IACxE,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,CAAC;IAClE,iBAAiB,GAAG,KAAK,CAAC;IAE1B,4EAA4E;IAC5E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,kBAAkB,EAAE,CAAC;KACrB;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\ninterface TaskQueueItem {\n\t/** The task to run */\n\ttask: () => void;\n}\n\n// A set of tasks that still have to be run\nlet taskQueue: TaskQueueItem[] = [];\n\n// Set to true when we have a pending idle task scheduled\nlet idleTaskScheduled = false;\n\n/**\n * A function that schedules a non critical task to be run when the browser has cycles available\n * @param task - The task to be executed\n * @param options - Optional configuration for the task execution\n */\nexport function scheduleIdleTask(task: () => void) {\n\ttaskQueue.push({\n\t\ttask,\n\t});\n\n\tensureIdleCallback();\n}\n\n/**\n * Ensures an idle callback has been scheduled for the remaining tasks\n */\nfunction ensureIdleCallback() {\n\tif (!idleTaskScheduled) {\n\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\tif (window.requestIdleCallback) {\n\t\t\twindow.requestIdleCallback(idleTaskCallback);\n\t\t} else {\n\t\t\tconst deadline = Date.now() + 50;\n\t\t\twindow.setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\tidleTaskCallback({\n\t\t\t\t\t\ttimeRemaining: () => Math.max(deadline - Date.now(), 0),\n\t\t\t\t\t\tdidTimeout: false,\n\t\t\t\t\t}),\n\t\t\t\t0,\n\t\t\t);\n\t\t}\n\t\tidleTaskScheduled = true;\n\t}\n}\n\n/**\n * Runs tasks from the task queue\n * @param filter - An optional function that will be called for each task to see if it should run.\n * Returns false for tasks that should not run. If omitted all tasks run.\n * @param shouldContinueRunning - An optional function that will be called to determine if\n * we have enough time to continue running tasks. If omitted, we don't stop running tasks.\n */\nfunction runTasks(\n\tfilter?: (taskQueueItem: TaskQueueItem) => boolean,\n\tshouldContinueRunning?: () => boolean,\n) {\n\t// The next value for the task queue\n\tconst newTaskQueue: TaskQueueItem[] = [];\n\n\tfor (let index = 0; index < taskQueue.length; index += 1) {\n\t\tif (shouldContinueRunning && !shouldContinueRunning()) {\n\t\t\t// Add the tasks we didn't get to to the end of the new task queue\n\t\t\tnewTaskQueue.push(...taskQueue.slice(index));\n\t\t\tbreak;\n\t\t}\n\n\t\tconst taskQueueItem = taskQueue[index];\n\n\t\tif (filter && !filter(taskQueueItem)) {\n\t\t\tnewTaskQueue.push(taskQueueItem);\n\t\t} else {\n\t\t\ttaskQueueItem.task();\n\t\t}\n\t}\n\n\ttaskQueue = newTaskQueue;\n}\n\n// Runs all the tasks in the task queue\nfunction idleTaskCallback(deadline: { timeRemaining: () => number; readonly didTimeout: boolean }) {\n\t// Minimum time that must be available on deadline to run any more tasks\n\tconst minTaskTime = 10;\n\trunTasks(undefined, () => deadline.timeRemaining() > minTaskTime);\n\tidleTaskScheduled = false;\n\n\t// If we didn't run through the entire queue, schedule another idle callback\n\tif (taskQueue.length > 0) {\n\t\tensureIdleCallback();\n\t}\n}\n"]}
package/jest.config.js CHANGED
@@ -4,9 +4,9 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- roots: ["<rootDir>/dist"],
8
- testEnvironment: "jsdom",
9
- testMatch: ["**/?(*.)+(spec|test).[j]s"],
10
- testPathIgnorePatterns: ["/node_modules/"],
11
- verbose: true,
7
+ roots: ["<rootDir>/dist"],
8
+ testEnvironment: "jsdom",
9
+ testMatch: ["**/?(*.)+(spec|test).[j]s"],
10
+ testPathIgnorePatterns: ["/node_modules/"],
11
+ verbose: true,
12
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.d.ts","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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jD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAE1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,MAAM,EAAE,gBAAgB;IAuDvB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB9C,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAiBzC,gBAAgB;IAkEjB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CA8B/D"}
package/lib/FluidCache.js CHANGED
@@ -24,8 +24,8 @@ export class FluidCache {
24
24
  // more detailed information on how the storage is being used
25
25
  let indexedDBSize;
26
26
  if ("usageDetails" in estimate) {
27
- indexedDBSize = estimate
28
- .usageDetails.indexedDB;
27
+ indexedDBSize = estimate.usageDetails
28
+ .indexedDB;
29
29
  }
30
30
  this.logger.sendTelemetryEvent({
31
31
  eventName: "FluidCacheStorageInfo" /* FluidCacheStorageInfo */,
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACH,8BAA8B,EAC9B,0BAA0B,EAC1B,mBAAmB,GACtB,MAAM,uBAAuB,CAAC;AAoC/B;;GAEG;AACH,MAAM,OAAO,UAAU;IAOnB,YAAY,MAAwB;QAChC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,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AAO,KAAU,EAAE;YACjB,uDAAuD;YACvD,6DAA6D;YAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CACtB,EAAE,SAAS,+CAAyC,EAAE,EACtD,KAAK,CACR,CAAC;SACL;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IPersistedCache,\n ICacheEntry,\n IFileEntry,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n ITelemetryBaseLogger,\n ITelemetryLogger,\n} from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask\";\nimport {\n getFluidCacheIndexedDbInstance,\n FluidDriverObjectStoreName,\n getKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb\";\nimport {\n FluidCacheErrorEvent,\n FluidCacheEventSubCategories,\n FluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry\";\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 indexedDB: number | undefined;\n}\n\nexport interface FluidCacheConfig {\n /**\n * A string to specify what partition of the cache you wish to use (e.g. a user id).\n * Null can be used to explicity indicate no partitioning, and has been chosen\n * vs undefined so that it is clear this is an intentional choice by the caller.\n * A null value should only be used when the host can ensure that the cache is not able\n * to be shared with multiple users.\n */\n // eslint-disable-next-line @rushstack/no-new-null\n partitionKey: string | null;\n\n /**\n * A logger that can be used to get insight into cache performance and errors\n */\n logger?: ITelemetryBaseLogger;\n\n /**\n * A value in milliseconds that determines the maximum age of a cache entry to return.\n * If an entry exists in the cache, but is older than this value, the cached value will not be returned.\n */\n maxCacheItemAge: number;\n}\n\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance\n */\nexport class FluidCache implements IPersistedCache {\n private readonly logger: ITelemetryLogger;\n\n private readonly partitionKey: string | null;\n\n private readonly maxCacheItemAge: number;\n\n constructor(config: FluidCacheConfig) {\n this.logger = ChildLogger.create(config.logger);\n this.partitionKey = config.partitionKey;\n this.maxCacheItemAge = config.maxCacheItemAge;\n\n scheduleIdleTask(async () => {\n // Log how much storage space is currently being used by indexed db.\n // NOTE: This API is not supported in all browsers and it doesn't let you see the size of a specific DB.\n // Exception added when eslint rule was added, this should be revisited when modifying this code\n if (navigator.storage?.estimate) {\n const estimate = await navigator.storage.estimate();\n\n // Some browsers have a usageDetails property that will tell you\n // more detailed information on how the storage is being used\n let indexedDBSize: number | undefined;\n if (\"usageDetails\" in estimate) {\n indexedDBSize = (\n (estimate as any)\n .usageDetails as StorageQuotaUsageDetails\n ).indexedDB;\n }\n\n this.logger.sendTelemetryEvent({\n eventName: FluidCacheGenericEvent.FluidCacheStorageInfo,\n subCategory: FluidCacheEventSubCategories.FluidCache,\n quota: estimate.quota,\n usage: estimate.usage,\n indexedDBSize,\n });\n }\n });\n\n scheduleIdleTask(async () => {\n // Delete entries that have not been accessed recently to clean up space\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n const index = transaction.store.index(\"lastAccessTimeMs\");\n // Get items that have not been accessed in 4 weeks\n const keysToDelete = await index.getAllKeys(\n IDBKeyRange.upperBound(\n new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000,\n ),\n );\n\n await Promise.all(\n keysToDelete.map((key) => transaction.store.delete(key)),\n );\n await transaction.done;\n } catch (error: any) {\n this.logger.sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n },\n error,\n );\n }\n });\n }\n\n public async removeEntries(file: IFileEntry): Promise<void> {\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n const index = transaction.store.index(\"fileId\");\n\n const keysToDelete = await index.getAllKeys(file.docId);\n\n await Promise.all(\n keysToDelete.map((key) => transaction.store.delete(key)),\n );\n await transaction.done;\n } catch (error: any) {\n this.logger.sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldEntriesError,\n },\n error,\n );\n }\n }\n\n public async get(cacheEntry: ICacheEntry): Promise<any> {\n const startTime = performance.now();\n\n const cachedItem = await this.getItemFromCache(cacheEntry);\n\n this.logger.sendPerformanceEvent({\n eventName: \"FluidCacheAccess\",\n cacheHit: cachedItem !== undefined,\n type: cacheEntry.type,\n duration: performance.now() - startTime,\n });\n\n // Value will contain metadata like the expiry time, we just want to return the object we were asked to cache\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return cachedItem?.cachedObject;\n }\n\n private async getItemFromCache(cacheEntry: ICacheEntry) {\n try {\n const key = getKeyForCacheEntry(cacheEntry);\n\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const value = await db.get(FluidDriverObjectStoreName, key);\n\n if (!value) {\n return undefined;\n }\n\n // If the data does not come from the same partition, don't return it\n if (value.partitionKey !== this.partitionKey) {\n this.logger.sendTelemetryEvent({\n eventName:\n FluidCacheGenericEvent.FluidCachePartitionKeyMismatch,\n subCategory: FluidCacheEventSubCategories.FluidCache,\n });\n\n return undefined;\n }\n\n const currentTime = new Date().getTime();\n\n // If too much time has passed since this cache entry was used, we will also return undefined\n if (currentTime - value.createdTimeMs > this.maxCacheItemAge) {\n return undefined;\n }\n\n const transaction = db.transaction(\n FluidDriverObjectStoreName,\n \"readwrite\",\n );\n // We don't want to block the get return of this function on updating the last accessed time\n // We catch this promise because there is no user bad if this is rejected.\n transaction.store\n .get(key)\n .then(async (valueToUpdate) => {\n // This value in the database could have been updated concurrently by other tabs/iframes\n // since we first read it. Only update the last accessed time if the current value in the\n // DB was the same one we returned.\n if (\n valueToUpdate !== undefined &&\n valueToUpdate.createdTimeMs === value.createdTimeMs &&\n (valueToUpdate.lastAccessTimeMs === undefined ||\n valueToUpdate.lastAccessTimeMs < currentTime)\n ) {\n await transaction.store.put(\n { ...valueToUpdate, lastAccessTimeMs: currentTime },\n key,\n );\n }\n await transaction.done;\n\n db.close();\n })\n .catch(() => { });\n return value;\n } catch (error: any) {\n // We can fail to open the db for a variety of reasons,\n // such as the database version having upgraded underneath us. Return undefined in this case\n this.logger.sendErrorEvent(\n { eventName: FluidCacheErrorEvent.FluidCacheGetError },\n error,\n );\n return undefined;\n }\n }\n\n public async put(entry: ICacheEntry, value: any): Promise<void> {\n try {\n const db = await getFluidCacheIndexedDbInstance(this.logger);\n\n const currentTime = new Date().getTime();\n\n await db.put(\n FluidDriverObjectStoreName,\n {\n cachedObject: value,\n fileId: entry.file.docId,\n type: entry.type,\n cacheItemId: entry.key,\n partitionKey: this.partitionKey,\n createdTimeMs: currentTime,\n lastAccessTimeMs: currentTime,\n },\n getKeyForCacheEntry(entry),\n );\n\n db.close();\n } catch (error: any) {\n // We can fail to open the db for a variety of reasons,\n // such as the database version having upgraded underneath us\n this.logger.sendErrorEvent(\n { eventName: FluidCacheErrorEvent.FluidCachePutError },\n error,\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"FluidCache.js","sourceRoot":"","sources":["../src/FluidCache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACN,8BAA8B,EAC9B,0BAA0B,EAC1B,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAoC/B;;GAEG;AACH,MAAM,OAAO,UAAU;IAOtB,YAAY,MAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAE9C,gBAAgB,CAAC,KAAK,IAAI,EAAE;;YAC3B,o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6DAA6D;YAC7D,IAAI,CAAC,MAAM,CAAC,cAAc,CACzB,EAAE,SAAS,+CAAyC,EAAE,EACtD,KAAK,CACL,CAAC;SACF;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IPersistedCache, ICacheEntry, IFileEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { scheduleIdleTask } from \"./scheduleIdleTask\";\nimport {\n\tgetFluidCacheIndexedDbInstance,\n\tFluidDriverObjectStoreName,\n\tgetKeyForCacheEntry,\n} from \"./FluidCacheIndexedDb\";\nimport {\n\tFluidCacheErrorEvent,\n\tFluidCacheEventSubCategories,\n\tFluidCacheGenericEvent,\n} from \"./fluidCacheTelemetry\";\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\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\n/**\n * A cache that can be used by the Fluid ODSP driver to cache data for faster performance\n */\nexport class FluidCache implements IPersistedCache {\n\tprivate readonly logger: ITelemetryLogger;\n\n\tprivate readonly partitionKey: string | null;\n\n\tprivate readonly maxCacheItemAge: number;\n\n\tconstructor(config: FluidCacheConfig) {\n\t\tthis.logger = ChildLogger.create(config.logger);\n\t\tthis.partitionKey = config.partitionKey;\n\t\tthis.maxCacheItemAge = config.maxCacheItemAge;\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});\n\t\t\t}\n\t\t});\n\n\t\tscheduleIdleTask(async () => {\n\t\t\t// Delete entries that have not been accessed recently to clean up space\n\t\t\ttry {\n\t\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t\tconst index = transaction.store.index(\"lastAccessTimeMs\");\n\t\t\t\t// Get items that have not been accessed in 4 weeks\n\t\t\t\tconst keysToDelete = await index.getAllKeys(\n\t\t\t\t\tIDBKeyRange.upperBound(new Date().getTime() - 4 * 7 * 24 * 60 * 60 * 1000),\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},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async removeEntries(file: IFileEntry): Promise<void> {\n\t\ttry {\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\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},\n\t\t\t\terror,\n\t\t\t);\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});\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\ttry {\n\t\t\tconst key = getKeyForCacheEntry(cacheEntry);\n\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\n\n\t\t\tconst value = await db.get(FluidDriverObjectStoreName, key);\n\n\t\t\tif (!value) {\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});\n\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\treturn undefined;\n\t\t\t}\n\n\t\t\tconst transaction = db.transaction(FluidDriverObjectStoreName, \"readwrite\");\n\t\t\t// We don't want to block the get return of this function on updating the last accessed time\n\t\t\t// We catch this promise because there is no user bad if this is rejected.\n\t\t\ttransaction.store\n\t\t\t\t.get(key)\n\t\t\t\t.then(async (valueToUpdate) => {\n\t\t\t\t\t// This value in the database could have been updated concurrently by other tabs/iframes\n\t\t\t\t\t// since we first read it. Only update the last accessed time if the current value in the\n\t\t\t\t\t// DB was the same one we returned.\n\t\t\t\t\tif (\n\t\t\t\t\t\tvalueToUpdate !== undefined &&\n\t\t\t\t\t\tvalueToUpdate.createdTimeMs === value.createdTimeMs &&\n\t\t\t\t\t\t(valueToUpdate.lastAccessTimeMs === undefined ||\n\t\t\t\t\t\t\tvalueToUpdate.lastAccessTimeMs < currentTime)\n\t\t\t\t\t) {\n\t\t\t\t\t\tawait transaction.store.put(\n\t\t\t\t\t\t\t{ ...valueToUpdate, lastAccessTimeMs: currentTime },\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait transaction.done;\n\n\t\t\t\t\tdb.close();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t\treturn value;\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 },\n\t\t\t\terror,\n\t\t\t);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tpublic async put(entry: ICacheEntry, value: any): Promise<void> {\n\t\ttry {\n\t\t\tconst db = await getFluidCacheIndexedDbInstance(this.logger);\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\n\t\t\tdb.close();\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 },\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FluidCacheIndexedDb.d.ts","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,QAAQ,EAAE,YAAY,EAAY,MAAM,KAAK,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAK1E,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAGzD,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAE7D,eAAO,MAAM,mBAAmB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B,GAAG,EAAE,CAAC,iBAAiB,CACzC,0BAA0B,CAC7B,CAAC;gBACF,gBAAgB,CAAC,WAAW,CACxB,eAAe,EACf,eAAe,CAClB,CAAC;gBACF,gBAAgB,CAAC,WAAW,CACxB,kBAAkB,EAClB,kBAAkB,CACrB,CAAC;gBACF,gBAAgB,CAAC,WAAW,CACxB,cAAc,EACd,cAAc,CACjB,CAAC;gBACF,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACV,MAAM,CACF,IAAI,KAAK,CACL,+EAA+E,CAClF,CACJ,CAAC;YACN,CAAC;SACJ,CACJ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC;AAED,mCAAmC;AACnC,+FAA+F;AAC/F,MAAM,UAAU,+BAA+B;IAC3C,OAAO,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { openDB, DBSchema, IDBPDatabase, deleteDB } from \"idb\";\nimport { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry\";\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 1: \"diverStorage\",\n 2: \"diverStorage.V2\",\n};\n\nexport function getKeyForCacheEntry(entry: ICacheEntry) {\n return `${entry.file.docId}_${entry.type}_${entry.key}`;\n}\n\nexport function getFluidCacheIndexedDbInstance(\n logger?: ITelemetryBaseLogger,\n): Promise<IDBPDatabase<FluidCacheDBSchema>> {\n return new Promise((resolve, reject) => {\n openDB<FluidCacheDBSchema>(\n FluidDriverCacheDBName,\n CurrentCacheVersion,\n {\n upgrade: (db, oldVersion) => {\n try {\n // We changed the format of the object store, so we must\n // delete the old stores to create a new one in V3\n const cacheToDelete = oldVersionNameMapping[oldVersion];\n if (cacheToDelete) {\n // We don't include the old object stores in the schema, so we need to\n // use a typecast here to prevent IDB from complaining\n db.deleteObjectStore(cacheToDelete as any);\n }\n } catch (error: any) {\n // Catch any error done when attempting to delete the older version.\n // If the object does not exist db will throw.\n // We can now assume that the old version is no longer there regardless.\n ChildLogger.create(logger).sendErrorEvent(\n {\n eventName:\n FluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n },\n error,\n );\n }\n\n const cacheObjectStore = db.createObjectStore(\n FluidDriverObjectStoreName,\n );\n cacheObjectStore.createIndex(\n \"createdTimeMs\",\n \"createdTimeMs\",\n );\n cacheObjectStore.createIndex(\n \"lastAccessTimeMs\",\n \"lastAccessTimeMs\",\n );\n cacheObjectStore.createIndex(\n \"partitionKey\",\n \"partitionKey\",\n );\n cacheObjectStore.createIndex(\"fileId\", \"fileId\");\n },\n blocked: () => {\n reject(\n new Error(\n \"Could not open DB since it is blocked by an older client that has the DB open\",\n ),\n );\n },\n },\n ).then(resolve, reject);\n });\n}\n\n// Deletes the indexed DB instance.\n// Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\nexport function deleteFluidCacheIndexDbInstance(): Promise<void> {\n return deleteDB(FluidDriverCacheDBName);\n}\n\n/**\n * Schema for the object store used to cache driver information\n */\nexport interface FluidCacheDBSchema extends DBSchema {\n [FluidDriverObjectStoreName]: {\n /**\n * A unique identifier for an item in the cache. It is a combination of file, type, and cacheItemId\n */\n key: string;\n\n value: {\n /**\n * The identifier of the file associated with the cache entry\n */\n fileId: string;\n\n /**\n * Describes the type of content being cached, such as snapshot\n */\n type: string;\n\n /**\n * Files may have multiple cached items associated with them,\n * this property uniquely identifies a specific cache entry for a file.\n * This is not globally unique, but rather a unique id for this file\n */\n cacheItemId: string;\n\n /*\n * Opaque object that the driver asks us to store in a cache for performance reasons\n */\n cachedObject: any;\n\n /**\n * A string to specify what partition of the cache you wish to use (e.g. a user id).\n * Null can be used to explicity indicate no partitioning.\n */\n // eslint-disable-next-line @rushstack/no-new-null\n partitionKey: string | null;\n\n /**\n * The time when the cache entry was put into the cache\n */\n createdTimeMs: number;\n\n /**\n * The last time the cache entry was used.\n * This is initially set to the time the cache entry was created Measured as ms since unix epoch.\n */\n lastAccessTimeMs: number;\n };\n\n indexes: {\n createdTimeMs: number;\n partitionKey: string;\n lastAccessTimeMs: number;\n fileId: string;\n };\n };\n}\n"]}
1
+ {"version":3,"file":"FluidCacheIndexedDb.js","sourceRoot":"","sources":["../src/FluidCacheIndexedDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAA0B,QAAQ,EAAE,MAAM,KAAK,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,+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,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;AAC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BAA+B;IAC9C,OAAO,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AACzC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { openDB, DBSchema, IDBPDatabase, deleteDB } from \"idb\";\nimport { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { FluidCacheErrorEvent } from \"./fluidCacheTelemetry\";\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 `${entry.file.docId}_${entry.type}_${entry.key}`;\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\tChildLogger.create(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// Deletes the indexed DB instance.\n// Warning this can throw an error in Firefox incognito, where accessing storage is prohibited.\nexport function deleteFluidCacheIndexDbInstance(): Promise<void> {\n\treturn deleteDB(FluidDriverCacheDBName);\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 */\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 +1 @@
1
- {"version":3,"file":"fluidCacheTelemetry.d.ts","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,sBAAsB;IACpC,uBAAuB,0BAA0B;IACjD,gCAAgC,mCAAmC;CACtE;AAED,0BAAkB,oBAAoB;IAClC,iCAAiC,oCAAoC;IACrE,oBAAoB,uBAAuB;IAC3C,oBAAoB,uBAAuB;IAC3C,4BAA4B,+BAA+B;IAC3D,4BAA4B,+BAA+B;CAC9D;AAED,0BAAkB,4BAA4B;IAC1C,YAAY,eAAe;CAC9B"}
1
+ {"version":3,"file":"fluidCacheTelemetry.d.ts","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,sBAAsB;IACvC,uBAAuB,0BAA0B;IACjD,gCAAgC,mCAAmC;CACnE;AAED,0BAAkB,oBAAoB;IACrC,iCAAiC,oCAAoC;IACrE,oBAAoB,uBAAuB;IAC3C,oBAAoB,uBAAuB;IAC3C,4BAA4B,+BAA+B;IAC3D,4BAA4B,+BAA+B;CAC3D;AAED,0BAAkB,4BAA4B;IAC7C,YAAY,eAAe;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"fluidCacheTelemetry.js","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum FluidCacheGenericEvent {\n \"FluidCacheStorageInfo\" = \"FluidCacheStorageInfo\",\n \"FluidCachePartitionKeyMismatch\" = \"FluidCachePartitionKeyMismatch\",\n}\n\nexport const enum FluidCacheErrorEvent {\n \"FluidCacheDeleteOldEntriesError\" = \"FluidCacheDeleteOldEntriesError\",\n \"FluidCacheGetError\" = \"FluidCacheGetError\",\n \"FluidCachePutError\" = \"FluidCachePutError\",\n \"FluidCacheUpdateUsageError\" = \"FluidCacheUpdateUsageError\",\n \"FluidCacheDeleteOldDbError\" = \"FluidCacheDeleteOldDbError\",\n}\n\nexport const enum FluidCacheEventSubCategories {\n \"FluidCache\" = \"FluidCache\",\n}\n"]}
1
+ {"version":3,"file":"fluidCacheTelemetry.js","sourceRoot":"","sources":["../src/fluidCacheTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum FluidCacheGenericEvent {\n\t\"FluidCacheStorageInfo\" = \"FluidCacheStorageInfo\",\n\t\"FluidCachePartitionKeyMismatch\" = \"FluidCachePartitionKeyMismatch\",\n}\n\nexport const enum FluidCacheErrorEvent {\n\t\"FluidCacheDeleteOldEntriesError\" = \"FluidCacheDeleteOldEntriesError\",\n\t\"FluidCacheGetError\" = \"FluidCacheGetError\",\n\t\"FluidCachePutError\" = \"FluidCachePutError\",\n\t\"FluidCacheUpdateUsageError\" = \"FluidCacheUpdateUsageError\",\n\t\"FluidCacheDeleteOldDbError\" = \"FluidCacheDeleteOldDbError\",\n}\n\nexport const enum FluidCacheEventSubCategories {\n\t\"FluidCache\" = \"FluidCache\",\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.0.0-internal.3.0.2";
8
+ export declare const pkgVersion = "2.0.0-internal.3.2.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.0.0-internal.3.0.2";
8
+ export const pkgVersion = "2.0.0-internal.3.2.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,sBAAsB,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.0.0-internal.3.0.2\";\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,sBAAsB,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.0.0-internal.3.2.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"scheduleIdleTask.js","sourceRoot":"","sources":["../src/scheduleIdleTask.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,2CAA2C;AAC3C,IAAI,SAAS,GAAoB,EAAE,CAAC;AAEpC,yDAAyD;AACzD,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAgB;IAC7C,SAAS,CAAC,IAAI,CAAC;QACX,IAAI;KACP,CAAC,CAAC;IAEH,kBAAkB,EAAE,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB;IACvB,IAAI,CAAC,iBAAiB,EAAE;QACpB,gGAAgG;QAChG,IAAI,MAAM,CAAC,mBAAmB,EAAE;YAC5B,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;SAChD;aAAM;YACH,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;YACjC,MAAM,CAAC,UAAU,CACb,GAAG,EAAE,CACD,gBAAgB,CAAC;gBACb,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBACvD,UAAU,EAAE,KAAK;aACpB,CAAC,EACN,CAAC,CACJ,CAAC;SACL;QACD,iBAAiB,GAAG,IAAI,CAAC;KAC5B;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CACb,MAAkD,EAClD,qBAAqC;IAErC,oCAAoC;IACpC,MAAM,YAAY,GAAoB,EAAE,CAAC;IAEzC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;QACtD,IAAI,qBAAqB,IAAI,CAAC,qBAAqB,EAAE,EAAE;YACnD,kEAAkE;YAClE,YAAY,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,MAAM;SACT;QAED,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YAClC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACpC;aAAM;YACH,aAAa,CAAC,IAAI,EAAE,CAAC;SACxB;KACJ;IAED,SAAS,GAAG,YAAY,CAAC;AAC7B,CAAC;AAED,uCAAuC;AACvC,SAAS,gBAAgB,CAAC,QAGzB;IACG,wEAAwE;IACxE,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,CAAC;IAClE,iBAAiB,GAAG,KAAK,CAAC;IAE1B,4EAA4E;IAC5E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACtB,kBAAkB,EAAE,CAAC;KACxB;AACL,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\ninterface TaskQueueItem {\n /** The task to run */\n task: () => void;\n}\n\n// A set of tasks that still have to be run\nlet taskQueue: TaskQueueItem[] = [];\n\n// Set to true when we have a pending idle task scheduled\nlet idleTaskScheduled = false;\n\n/**\n * A function that schedules a non critical task to be run when the browser has cycles available\n * @param task - The task to be executed\n * @param options - Optional configuration for the task execution\n */\nexport function scheduleIdleTask(task: () => void) {\n taskQueue.push({\n task,\n });\n\n ensureIdleCallback();\n}\n\n/**\n * Ensures an idle callback has been scheduled for the remaining tasks\n */\nfunction ensureIdleCallback() {\n if (!idleTaskScheduled) {\n // Exception added when eslint rule was added, this should be revisited when modifying this code\n if (window.requestIdleCallback) {\n window.requestIdleCallback(idleTaskCallback);\n } else {\n const deadline = Date.now() + 50;\n window.setTimeout(\n () =>\n idleTaskCallback({\n timeRemaining: () => Math.max(deadline - Date.now(), 0),\n didTimeout: false,\n }),\n 0,\n );\n }\n idleTaskScheduled = true;\n }\n}\n\n/**\n * Runs tasks from the task queue\n * @param filter - An optional function that will be called for each task to see if it should run.\n * Returns false for tasks that should not run. If omitted all tasks run.\n * @param shouldContinueRunning - An optional function that will be called to determine if\n * we have enough time to continue running tasks. If omitted, we don't stop running tasks.\n */\nfunction runTasks(\n filter?: (taskQueueItem: TaskQueueItem) => boolean,\n shouldContinueRunning?: () => boolean,\n) {\n // The next value for the task queue\n const newTaskQueue: TaskQueueItem[] = [];\n\n for (let index = 0; index < taskQueue.length; index += 1) {\n if (shouldContinueRunning && !shouldContinueRunning()) {\n // Add the tasks we didn't get to to the end of the new task queue\n newTaskQueue.push(...taskQueue.slice(index));\n break;\n }\n\n const taskQueueItem = taskQueue[index];\n\n if (filter && !filter(taskQueueItem)) {\n newTaskQueue.push(taskQueueItem);\n } else {\n taskQueueItem.task();\n }\n }\n\n taskQueue = newTaskQueue;\n}\n\n// Runs all the tasks in the task queue\nfunction idleTaskCallback(deadline: {\n timeRemaining: () => number;\n readonly didTimeout: boolean;\n}) {\n // Minimum time that must be available on deadline to run any more tasks\n const minTaskTime = 10;\n runTasks(undefined, () => deadline.timeRemaining() > minTaskTime);\n idleTaskScheduled = false;\n\n // If we didn't run through the entire queue, schedule another idle callback\n if (taskQueue.length > 0) {\n ensureIdleCallback();\n }\n}\n"]}
1
+ {"version":3,"file":"scheduleIdleTask.js","sourceRoot":"","sources":["../src/scheduleIdleTask.ts"],"names":[],"mappings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AS,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YACrC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACjC;aAAM;YACN,aAAa,CAAC,IAAI,EAAE,CAAC;SACrB;KACD;IAED,SAAS,GAAG,YAAY,CAAC;AAC1B,CAAC;AAED,uCAAuC;AACvC,SAAS,gBAAgB,CAAC,QAAuE;IAChG,wEAAwE;IACxE,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,CAAC;IAClE,iBAAiB,GAAG,KAAK,CAAC;IAE1B,4EAA4E;IAC5E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,kBAAkB,EAAE,CAAC;KACrB;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\ninterface TaskQueueItem {\n\t/** The task to run */\n\ttask: () => void;\n}\n\n// A set of tasks that still have to be run\nlet taskQueue: TaskQueueItem[] = [];\n\n// Set to true when we have a pending idle task scheduled\nlet idleTaskScheduled = false;\n\n/**\n * A function that schedules a non critical task to be run when the browser has cycles available\n * @param task - The task to be executed\n * @param options - Optional configuration for the task execution\n */\nexport function scheduleIdleTask(task: () => void) {\n\ttaskQueue.push({\n\t\ttask,\n\t});\n\n\tensureIdleCallback();\n}\n\n/**\n * Ensures an idle callback has been scheduled for the remaining tasks\n */\nfunction ensureIdleCallback() {\n\tif (!idleTaskScheduled) {\n\t\t// Exception added when eslint rule was added, this should be revisited when modifying this code\n\t\tif (window.requestIdleCallback) {\n\t\t\twindow.requestIdleCallback(idleTaskCallback);\n\t\t} else {\n\t\t\tconst deadline = Date.now() + 50;\n\t\t\twindow.setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\tidleTaskCallback({\n\t\t\t\t\t\ttimeRemaining: () => Math.max(deadline - Date.now(), 0),\n\t\t\t\t\t\tdidTimeout: false,\n\t\t\t\t\t}),\n\t\t\t\t0,\n\t\t\t);\n\t\t}\n\t\tidleTaskScheduled = true;\n\t}\n}\n\n/**\n * Runs tasks from the task queue\n * @param filter - An optional function that will be called for each task to see if it should run.\n * Returns false for tasks that should not run. If omitted all tasks run.\n * @param shouldContinueRunning - An optional function that will be called to determine if\n * we have enough time to continue running tasks. If omitted, we don't stop running tasks.\n */\nfunction runTasks(\n\tfilter?: (taskQueueItem: TaskQueueItem) => boolean,\n\tshouldContinueRunning?: () => boolean,\n) {\n\t// The next value for the task queue\n\tconst newTaskQueue: TaskQueueItem[] = [];\n\n\tfor (let index = 0; index < taskQueue.length; index += 1) {\n\t\tif (shouldContinueRunning && !shouldContinueRunning()) {\n\t\t\t// Add the tasks we didn't get to to the end of the new task queue\n\t\t\tnewTaskQueue.push(...taskQueue.slice(index));\n\t\t\tbreak;\n\t\t}\n\n\t\tconst taskQueueItem = taskQueue[index];\n\n\t\tif (filter && !filter(taskQueueItem)) {\n\t\t\tnewTaskQueue.push(taskQueueItem);\n\t\t} else {\n\t\t\ttaskQueueItem.task();\n\t\t}\n\t}\n\n\ttaskQueue = newTaskQueue;\n}\n\n// Runs all the tasks in the task queue\nfunction idleTaskCallback(deadline: { timeRemaining: () => number; readonly didTimeout: boolean }) {\n\t// Minimum time that must be available on deadline to run any more tasks\n\tconst minTaskTime = 10;\n\trunTasks(undefined, () => deadline.timeRemaining() > minTaskTime);\n\tidleTaskScheduled = false;\n\n\t// If we didn't run through the entire queue, schedule another idle callback\n\tif (taskQueue.length > 0) {\n\t\tensureIdleCallback();\n\t}\n}\n"]}