Skip to content

Commit 54fca68

Browse files
OdspDriver: Move IPersistedCache types to driver-definitions (#25518)
In an effort to decouple the driver web cache from the odsp driver a number of types have been moved from `@fluidframework/odsp-driver-definitions` to `@fluidframework/driver-definitions`. The moved types have been deprecated in `@fluidframework/odsp-driver-definitions`, and any usages should be moved to `@fluidframework/driver-definitions`. The moved type are: - `IEntry` - `IFileEntry` - `ICacheEntry` - `IPersistedCache` --------- Co-authored-by: jzaffiro <110866475+jzaffiro@users.noreply.github.com>
1 parent a14a81a commit 54fca68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+349
-237
lines changed

.changeset/stupid-ties-raise.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@fluidframework/driver-definitions": minor
3+
"@fluidframework/driver-web-cache": minor
4+
"@fluidframework/odsp-driver": minor
5+
"@fluidframework/odsp-driver-definitions": minor
6+
"__section": deprecation
7+
---
8+
Move IPersistedCache types to driver-definitions
9+
10+
In an effort to decouple the driver web cache from the odsp driver a number of types have been moved from `@fluidframework/odsp-driver-definitions` to `@fluidframework/driver-definitions`. The moved types have been deprecated in `@fluidframework/odsp-driver-definitions`, and any usages should be moved to `@fluidframework/driver-definitions`.
11+
12+
The moved types are:
13+
- `IEntry`
14+
- `IFileEntry`
15+
- `ICacheEntry`
16+
- `IPersistedCache`

examples/benchmarks/odspsnapshotfetch-perftestapp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
},
3636
"dependencies": {
3737
"@fluidframework/core-utils": "workspace:~",
38+
"@fluidframework/driver-definitions": "workspace:~",
39+
"@fluidframework/driver-utils": "workspace:~",
3840
"@fluidframework/odsp-doclib-utils": "workspace:~",
3941
"@fluidframework/odsp-driver": "workspace:~",
40-
"@fluidframework/odsp-driver-definitions": "workspace:~",
4142
"@fluidframework/odsp-urlresolver": "workspace:~",
4243
"@fluidframework/telemetry-utils": "workspace:~",
4344
"@fluidframework/tool-utils": "workspace:~",

examples/benchmarks/odspsnapshotfetch-perftestapp/src/odspPersistantCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import {
6+
import type {
77
ICacheEntry,
88
IFileEntry,
99
IPersistedCache,
10-
getKeyForCacheEntry,
11-
} from "@fluidframework/odsp-driver-definitions/internal";
10+
} from "@fluidframework/driver-definitions/internal";
11+
import { getKeyForCacheEntry } from "@fluidframework/driver-utils/internal";
1212

1313
export class OdspSampleCache implements IPersistedCache {
1414
private readonly cache = new Map<string, any>();

examples/utils/webpack-fluid-loader/src/getDocumentServiceFactory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
*/
55

66
import { assert } from "@fluidframework/core-utils/internal";
7-
import { IDocumentServiceFactory } from "@fluidframework/driver-definitions/internal";
7+
import {
8+
IDocumentServiceFactory,
9+
type IPersistedCache,
10+
} from "@fluidframework/driver-definitions/internal";
811
import {
912
LocalDocumentServiceFactory,
1013
LocalSessionStorageDbFactory,
1114
} from "@fluidframework/local-driver/internal";
1215
import { OdspDocumentServiceFactory } from "@fluidframework/odsp-driver/internal";
13-
import {
14-
HostStoragePolicy,
15-
IPersistedCache,
16-
} from "@fluidframework/odsp-driver-definitions/internal";
16+
import { HostStoragePolicy } from "@fluidframework/odsp-driver-definitions/internal";
1717
import { RouterliciousDocumentServiceFactory } from "@fluidframework/routerlicious-driver/internal";
1818
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
1919
import { InsecureTokenProvider } from "@fluidframework/test-runtime-utils/internal";

examples/utils/webpack-fluid-loader/src/loader.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ import { IUser } from "@fluidframework/driver-definitions";
2323
import {
2424
IDocumentServiceFactory,
2525
IResolvedUrl,
26+
type IPersistedCache,
2627
} from "@fluidframework/driver-definitions/internal";
2728
import { InsecureUrlResolver } from "@fluidframework/driver-utils/internal";
2829
import {
2930
LocalDocumentServiceFactory,
3031
LocalResolver,
3132
} from "@fluidframework/local-driver/internal";
3233
import { prefetchLatestSnapshot } from "@fluidframework/odsp-driver/internal";
33-
import {
34-
HostStoragePolicy,
35-
IPersistedCache,
36-
} from "@fluidframework/odsp-driver-definitions/internal";
34+
import { HostStoragePolicy } from "@fluidframework/odsp-driver-definitions/internal";
3735
import { RequestParser } from "@fluidframework/runtime-utils/internal";
3836
import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
3937
import sillyname from "sillyname";

examples/utils/webpack-fluid-loader/src/odspPersistantCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
ICacheEntry,
88
IFileEntry,
99
IPersistedCache,
10-
getKeyForCacheEntry,
11-
} from "@fluidframework/odsp-driver-definitions/internal";
10+
} from "@fluidframework/driver-definitions/internal";
11+
import { getKeyForCacheEntry } from "@fluidframework/driver-utils/internal";
1212

1313
export class OdspPersistentCache implements IPersistedCache {
1414
private readonly cache = new Map<string, any>();

packages/common/driver-definitions/api-report/driver-definitions.legacy.beta.api.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export interface IBranchOrigin {
113113
sequenceNumber: number;
114114
}
115115

116+
// @beta @legacy
117+
export interface ICacheEntry extends IEntry {
118+
file: IFileEntry;
119+
}
120+
116121
// @public
117122
export interface ICapabilities {
118123
interactive: boolean;
@@ -319,6 +324,19 @@ export interface IDriverErrorBase {
319324
online?: string;
320325
}
321326

327+
// @beta @legacy
328+
export interface IEntry {
329+
key: string;
330+
type: string;
331+
}
332+
333+
// @beta @legacy
334+
export interface IFileEntry {
335+
docId: string;
336+
fileVersion?: string;
337+
resolvedUrl: IResolvedUrl;
338+
}
339+
322340
// @beta @legacy (undocumented)
323341
export interface IGenericNetworkError extends IDriverErrorBase {
324342
// (undocumented)
@@ -350,6 +368,13 @@ export interface INackContent {
350368
type: NackErrorType;
351369
}
352370

371+
// @beta @legacy
372+
export interface IPersistedCache {
373+
get(entry: ICacheEntry): Promise<unknown>;
374+
put(entry: ICacheEntry, value: unknown): Promise<void>;
375+
removeEntries(file: IFileEntry): Promise<void>;
376+
}
377+
353378
// @beta @legacy (undocumented)
354379
export interface IProcessMessageResult {
355380
// (undocumented)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import type { IResolvedUrl } from "./urlResolver.js";
7+
8+
/**
9+
* File / container identifier.
10+
* There is overlapping information here - host can use all of it or parts
11+
* to implement storage / identify files.
12+
* @legacy @beta
13+
*/
14+
export interface IFileEntry {
15+
/**
16+
* Unique and stable ID of the document.
17+
* Driver guarantees that docId is stable ID uniquely identifying document.
18+
*/
19+
docId: string;
20+
/**
21+
* Resolved URI is provided for additional versatility - host can use it to
22+
* identify file in storage, and (as example) delete all cached entries for
23+
* a file if user requests so.
24+
* This is IOdspResolvedUrl in case of ODSP driver.
25+
*/
26+
resolvedUrl: IResolvedUrl;
27+
28+
/**
29+
* Optional version of the file.
30+
*/
31+
fileVersion?: string;
32+
}
33+
34+
/**
35+
* Cache entry. Identifies file that this entry belongs to, and type of content stored in it.
36+
* @legacy @beta
37+
*/
38+
export interface IEntry {
39+
/**
40+
* Identifies type of entry for a given file.
41+
* Each file can have multiple types of entries associated with it.
42+
* For example, it can be snapshot, blob, ops, etc.
43+
*/
44+
type: string;
45+
46+
/**
47+
* Identifies individual entry for a given file and type.
48+
* Each file can have multiple cache entries associated with it.
49+
* This property identifies a particular instance of entry.
50+
* For example, for blobs it will be unique ID of the blob in a file.
51+
* For batch of ops, it can be starting op sequence number.
52+
* For types that have only one entry (like snapshots), it will be empty string.
53+
*/
54+
key: string;
55+
}
56+
57+
/**
58+
* Cache entry. Identifies file that this entry belongs to, and type of content stored in it.
59+
* @legacy @beta
60+
*/
61+
export interface ICacheEntry extends IEntry {
62+
/**
63+
* Identifies file in storage this cached entry is for
64+
*/
65+
file: IFileEntry;
66+
}
67+
68+
/**
69+
* Persistent cache. This interface can be implemented by the host to provide durable caching
70+
* across sessions. If not provided at driver factory construction, factory will use in-memory
71+
* cache implementation that does not survive across sessions. Snapshot entires stored in the
72+
* IPersistedCache will be considered stale and removed after 2 days. Read the README for more
73+
* information.
74+
* @legacy @beta
75+
*/
76+
export interface IPersistedCache {
77+
/**
78+
* Get the cache value of the key
79+
* @param entry - cache entry, identifies file and particular key for this file.
80+
* @returns Cached value. undefined if nothing is cached.
81+
*/
82+
get(entry: ICacheEntry): Promise<unknown>;
83+
84+
/**
85+
* Put the value into cache.
86+
* Important - only serializable content is allowed since this cache may be persisted between sessions
87+
* @param entry - cache entry.
88+
* @param value - JSON-serializable content.
89+
*/
90+
put(entry: ICacheEntry, value: unknown): Promise<void>;
91+
92+
/**
93+
* Removes the entries from the cache for given parameters.
94+
* @param file - file entry to be deleted.
95+
*/
96+
removeEntries(file: IFileEntry): Promise<void>;
97+
}

packages/common/driver-definitions/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
* Licensed under the MIT License.
44
*/
55

6+
export type {
7+
ICacheEntry,
8+
IEntry,
9+
IFileEntry,
10+
IPersistedCache,
11+
} from "./cacheDefinitions.js";
12+
613
export type {
714
DriverError,
815
IAnyDriverError,

packages/drivers/driver-web-cache/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
"dependencies": {
9292
"@fluidframework/core-interfaces": "workspace:~",
9393
"@fluidframework/core-utils": "workspace:~",
94-
"@fluidframework/odsp-driver-definitions": "workspace:~",
94+
"@fluidframework/driver-definitions": "workspace:~",
95+
"@fluidframework/driver-utils": "workspace:~",
9596
"@fluidframework/telemetry-utils": "workspace:~",
9697
"idb": "^6.1.2"
9798
},

0 commit comments

Comments
 (0)