synology_apm_repo.sdk.storage.dircache module

DirCache — the directory-listing cache behind resolve_seq_file’s “logical name -> [physical names]” lookups for per-generation files (.buk, .inf, .fgp, .ref, …).

Re-listing a directory on every lookup would make an export touching a few hundred buckets do O(n^2) scans (hundreds of paginated list calls on object storage), so each opened repository keeps DirCache instances for its lifetime, bounded by count; invalidate() (reached through CacheManager) forces a re-scan.

generations.py’s db/<name> generation selection lists through this cache’s flat listdir (DedupRepo’s fixed-directory instance), so the several db/<name> resolutions of one repository share three listings.

synology_apm_repo.sdk.storage.dircache.split_seq_suffix(name)

Split a trailing .<digits> sequence-id suffix off name (FORMAT-SPEC.md: Sequence-id suffix mechanism). Returns (name, None) if there is none. Only the last dot-segment counts: "132.buk.1" -> ("132.buk", 1), "132.buk" -> ("132.buk", None).

class synology_apm_repo.sdk.storage.dircache.DirCache(store, *, maxsize=256)

Bases: object

Bounded cache of directory listings, keyed by store-relative directory path. One listing per cached directory; the grouped index and any sizes the backend reported with it are kept, and listdir is derived from them, so a directory costs one entry however it is asked for.

maxsize bounds the directories held (LRU). Tasks racing on the same cold directory share one listing.

async listdir(dir_path)

The entry names store.listdir(dir_path) reports, sorted, from the cached listing.

async grouped(dir_path)

{logical_name: [physical_name, ...]} for dir_path. logical_name is the entry with any sequence-id suffix stripped (split_seq_suffix).

async entry_sizes(dir_path)

Every entry name in dir_path with the size the listing reported for it (None: no size, or a directory), from the cached listing.

async size_of(dir_path, name)

The size of name (a physical entry name) in dir_path as the listing itself reported it, with no extra request; None when the listing had no size for it, name is a directory, or it is absent.

stats()

Counters of the underlying directory cache.

invalidate(dir_path=None)

Drop the cached entry for dir_path (or everything, if omitted).