Skip to content

Repo cache

getRepoCache(ownerKey, repoName) / invalidateRepoCache(ownerKey, repoName)

Section titled “getRepoCache(ownerKey, repoName) / invalidateRepoCache(ownerKey, repoName)”
import { getRepoCache, invalidateRepoCache } from 'git-edge';
const repo = { fs, gitdir, cache: getRepoCache('alice', 'blog') };

isomorphic-git re-parses a packfile index from scratch on every readTree/log/readObject call unless callers share a cache object across calls — without one, an operation that touches many objects (walking commit history, a deep diff) pays that parse cost hundreds of times in a single request. getRepoCache returns a long-lived, per-repo object, keyed `${ownerKey}/${repoName}`, created on first access and reused across every subsequent call for that same repo within the process. At most 32 repos are held at once; adding a new one evicts the least recently used. Nothing is held on disk, so the cache is per-process and starts empty.

Call invalidateRepoCache(ownerKey, repoName) after anything rewrites a repo’s storage independently of the process holding this cache — a rename, a bulk resync, a repack that ran elsewhere — so stale parsed pack state can’t leak into the next read.

await renameRepo('alice', 'blog', 'blog-v2');
invalidateRepoCache('alice', 'blog');