IF Commons GitHub

logical/layers/cached

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-anyfs-middleware FR-006

The cached layer: a read goes through a cache that is itself a store. A read asks the origin for the revision of the path, which is cheap, and gives the cached bytes where the revision is the one cached; it fetches and keeps the bytes otherwise. A write or a delete goes to the origin and drops the cached copy, whatever it ends with, because a failed write leaves the object in an unknown state. The cache is never trusted over the origin: the revision the origin gives decides.

The cache keeps two objects for each path, the bytes under d/<path> and the revision they were read at under r/<path>. A batch, a rename, an append, a ranged read and a search are not carried: the cache could not keep them in step.

import { cached } from "./cached.ts";
// const store = cached(origin, memoryStore)

Source: commons/anyfs/src/logical/layers/cached.ts

1 of 2 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

UNCACHEABLEconstno test imports it
const UNCACHEABLE: readonly ["batch", "rename", "append", "rangeRead", "search", "merge"]

The capabilities a cache cannot keep in step.

cachedfunction
function cached<C extends Capability>(origin: StoreBase & UnionToIntersection<{ [K in C]: Group<K, C>; }[C]> & { readonly "@anyfs/capabilities"?: ((capability: C) => void) | undefined; } & NoInfer<Store<"read" | "stat">>, cache: Store<"delete" | "read" | "write">): Store<Exclude<C, "append" | "batch" | "lock" | "merge" | "rangeRead" | "rename" | "search" | "watch">>

A store that reads through a cache and keeps the capabilities of its origin but those a cache cannot keep.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.