import { ReplicaCache } from "https://deno.land/x/earthstar@v9.3.3/mod.ts";
A cached, synchronous interface to a replica, useful for reactive abstractions. Always returns results from its cache, and proxies the query to the backing replica in case of a cache miss.
const cache = new ReplicaCache(myReplica);
const pngQuery = { filter: { pathEndsWith: ".png" } };
let pngDocs = cache.queryDocs(pngQuery);
cache.onCacheUpdate(() => {
pngDocs = cache.queryDocs(pngQuery);
});
Constructors
Properties
Methods
Fetch all versions of all docs from the cache. Returns an empty array in case of a cache miss, and queries the backing replica.
Fetch all versions of all docs from a certain path from the cache. Returns an empty array in case of a cache miss, and queries the backing replica.
Fetch latest version of a doc at a path from the cache. Returns an empty array in case of a cache miss, and queries the backing replica.
Fetch latest versions of all docs from the cache. Returns an empty array in case of a cache miss, and queries the backing replica.
Subscribes to the cache, calling a callback when previously returned results can be considered stale. Returns a function for unsubscribing.