/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IResolvedUrl } from "./urlResolver.js"; /** * File / container identifier. * There is overlapping information here - host can use all of it or parts * to implement storage / identify files. * @legacy @beta */ export interface IFileEntry { /** * Unique and stable ID of the document. * Driver guarantees that docId is stable ID uniquely identifying document. */ docId: string; /** * Resolved URI is provided for additional versatility - host can use it to * identify file in storage, and (as example) delete all cached entries for * a file if user requests so. * This is IOdspResolvedUrl in case of ODSP driver. */ resolvedUrl: IResolvedUrl; /** * Optional version of the file. */ fileVersion?: string; } /** * Cache entry. Identifies file that this entry belongs to, and type of content stored in it. * @legacy @beta */ export interface IEntry { /** * Identifies type of entry for a given file. * Each file can have multiple types of entries associated with it. * For example, it can be snapshot, blob, ops, etc. */ type: string; /** * Identifies individual entry for a given file and type. * Each file can have multiple cache entries associated with it. * This property identifies a particular instance of entry. * For example, for blobs it will be unique ID of the blob in a file. * For batch of ops, it can be starting op sequence number. * For types that have only one entry (like snapshots), it will be empty string. */ key: string; } /** * Cache entry. Identifies file that this entry belongs to, and type of content stored in it. * @legacy @beta */ export interface ICacheEntry extends IEntry { /** * Identifies file in storage this cached entry is for */ file: IFileEntry; } /** * Persistent cache. This interface can be implemented by the host to provide durable caching * across sessions. If not provided at driver factory construction, factory will use in-memory * cache implementation that does not survive across sessions. Snapshot entires stored in the * IPersistedCache will be considered stale and removed after 2 days. Read the README for more * information. * @legacy @beta */ export interface IPersistedCache { /** * Get the cache value of the key * @param entry - cache entry, identifies file and particular key for this file. * @returns Cached value. undefined if nothing is cached. */ get(entry: ICacheEntry): Promise; /** * Put the value into cache. * Important - only serializable content is allowed since this cache may be persisted between sessions * @param entry - cache entry. * @param value - JSON-serializable content. */ put(entry: ICacheEntry, value: unknown): Promise; /** * Removes the entries from the cache for given parameters. * @param file - file entry to be deleted. */ removeEntries(file: IFileEntry): Promise; /** * Removes a specific entry from the cache. * @param entry - cache entry to be deleted. */ removeEntry?(entry: ICacheEntry): Promise; /** * Atomically read the currently-cached value, hand it to `updater`, and write a new value * iff `updater` calls the supplied `set` callback inside the same atomic transaction. * Enables compare-and-set / read-modify-write across consumers that share the underlying * storage (for example, multiple browser tabs). * * Implementations must invoke `updater` synchronously between reading the existing value * and committing the write, so the get/decide/put runs atomically. The updater is passed * `(existing, set)`; calling `set(value)` schedules a write, calling `set(undefined)` * schedules a delete of the row at the key, and returning without calling `set` leaves * the cache untouched. If the updater throws, the existing row is preserved. * * @param entry - cache entry, identifies file and particular key for this file. * @param updater - synchronous callback invoked with `(existing, set)`. `existing` matches * what `get` would return (typically `undefined` when the row is missing or invisible * under implementation-specific staleness rules). * @returns `true` if `set` was called and the write (or delete) committed; `false` if the * updater returned without calling `set`, threw, or the implementation observed an error. */ update?(entry: ICacheEntry, updater: (existing: unknown, set: (value: unknown) => void) => void): Promise; } //# sourceMappingURL=cacheDefinitions.d.ts.map