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 |
_fallback |
Callable[[], Mapping[int, Any]] | None
|
A loader of objects whose sources live outside |
_locate |
Callable[[int], Group | None] | None
|
Maps a cache ID to an HDF5 subtree of |
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 |
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 |
_fallback |
Callable[[], Mapping[int, Any]] | None
|
A loader of objects whose sources live outside |
_locate |
Callable[[int], Group | None] | None
|
Maps a cache ID to an HDF5 subtree of |
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. |