Skip to content

ResolvingDecodeCache

Bases: dict

A decode cache that resolves a missing source object on demand by scanning _root for it, rather than assuming top-down traversal has already decoded it before a reference to it is reached.

Attributes:

Name Type Description
_root File | Group | dict

The structure to search for a source node; mutable so it can be re-pointed (e.g. to a fresh file handle) after construction.

_format {'hdf5', 'json'}

The format of _root.

_fallback Callable[[], Mapping[int, Any]] | None

A loader of objects whose sources live outside _root, consulted on a miss before _root is scanned.

_locate Callable[[int], Group | None] | None

Maps a cache ID to an HDF5 subtree of _root that should hold its source, or None. Searched before _root; on a miss _root is scanned as usual. Mutable like _root; default None.

ResolvingDecodeCache

ResolvingDecodeCache(root, format, fallback=None)

Initialize the cache with a root structure to search.

Parameters:

Name Type Description Default
root File | Group | dict

The root structure (HDF5 file/group or JSON dict) to search for sources.

required
format ('hdf5', 'json')

The format of the root structure.

'hdf5'
fallback Callable[[], Mapping[int, Any]] | None

A loader of objects whose sources live outside root, by cache ID. It is called on each miss, so it should be cheap after its first call. A missing ID found in its mapping is stored and returned without scanning root; otherwise root is scanned.

None

Name Type Description
_root File | Group | dict

The structure to search for a source node; mutable so it can be re-pointed (e.g. to a fresh file handle) after construction.

_format {'hdf5', 'json'}

The format of _root.

_fallback Callable[[], Mapping[int, Any]] | None

A loader of objects whose sources live outside _root, consulted on a miss before _root is scanned.

_locate Callable[[int], Group | None] | None

Maps a cache ID to an HDF5 subtree of _root that should hold its source, or None. Searched before _root; on a miss _root is scanned as usual. Mutable like _root; default None.

resolve

resolve(cache_id)

Return the cached object, or locate and decode its source if missing.

Parameters:

Name Type Description Default
cache_id int

The cache ID to resolve.

required

Returns:

Type Description
Serializable | DeferredRef

The decoded object (or a DeferredRef placeholder).

Raises:

Type Description
RuntimeError

If no matching source node is found in the root structure.