FluidCache Class
A cache that can be used by the Fluid ODSP driver to cache data for faster performance.
To use, import via @fluidframework/driver-web-cache/legacy.
For more information about our API support guarantees, see here.
Signature
export declare class FluidCache implements IPersistedCache
Implements: IPersistedCache
Constructors
| Constructor | Alerts | Description |
|---|---|---|
| (constructor)(config) | Beta | Constructs a new instance of the FluidCache class |
Methods
| Method | Alerts | Return Type | Description |
|---|---|---|---|
| get(cacheEntry) | Beta | Promise<any> | |
| put(entry, value) | Beta | Promise<void> | |
| removeEntries(file) | Beta | Promise<void> | |
| removeEntry(entry) | Beta | Promise<void> | |
| update(entry, updater) | Beta | Promise<boolean> | Atomically reads the existing cached entry, hands it to updater, and writes a new value iff updater calls the supplied set callback. The read and the conditional write happen inside a single IndexedDB readwrite transaction, so the decision sees a consistent view across consumers sharing the same underlying IndexedDB instance (for example, multiple browser tabs racing to persist pending state). |
Constructor Details
(constructor)
Constructs a new instance of the FluidCache class
For more information about our API support guarantees, see here.
Signature
constructor(config: FluidCacheConfig);
Parameters
| Parameter | Type | Description |
|---|---|---|
| config | FluidCacheConfig |
Method Details
get
For more information about our API support guarantees, see here.
Signature
get(cacheEntry: ICacheEntry): Promise<any>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| cacheEntry | ICacheEntry |
Returns
Return type: Promise<any>
put
For more information about our API support guarantees, see here.
Signature
put(entry: ICacheEntry, value: any): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| entry | ICacheEntry | |
| value | any |
Returns
Return type: Promise<void>
removeEntries
For more information about our API support guarantees, see here.
Signature
removeEntries(file: IFileEntry): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| file | IFileEntry |
Returns
Return type: Promise<void>
removeEntry
For more information about our API support guarantees, see here.
Signature
removeEntry(entry: ICacheEntry): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| entry | ICacheEntry |
Returns
Return type: Promise<void>
update
Atomically reads the existing cached entry, hands it to updater, and writes a new value iff updater calls the supplied set callback. The read and the conditional write happen inside a single IndexedDB readwrite transaction, so the decision sees a consistent view across consumers sharing the same underlying IndexedDB instance (for example, multiple browser tabs racing to persist pending state).
For more information about our API support guarantees, see here.
Signature
update(entry: ICacheEntry, updater: (existing: unknown, set: (value: unknown) => void) => void): Promise<boolean>;
Remarks
The implementation uses transaction.store.get + transaction.store.put rather than an IDB cursor. Both run inside the same readwrite transaction, so the atomicity guarantee is identical, and the get/put pair is materially simpler to reason about for a single-key update. A cursor would be the right tool if we needed to iterate or range-scan; for a known key we don't.
Parameters
| Parameter | Type | Description |
|---|---|---|
| entry | ICacheEntry | cache entry; identifies the file and the key within that file. |
| updater | (existing: unknown, set: (value: unknown) => void) => void | synchronous callback invoked with Calling The updater itself must be synchronous and When Exceptions thrown by Compare-and-set callers: a |
Returns
true if updater called set and the write committed; false if updater returned without calling set, threw, or an IDB error occurred. IDB errors are logged and not thrown, matching the behavior of put.
Return type: Promise<boolean>