Skip to content

cache

cache #

The single cache node — store a value at a path and return it.

CacheProcedure replaces the old file/bundle variants: the destination is a Path[T] position, which already encodes whether it is a file or a directory bundle, so one node covers both. It type-checks the value against the position by structure, runs the value procedure, stores the result, and returns it (so the cached value can flow on as T).

CacheProcedure #

Bases: Procedure[T]

Store value at destination and return the cached value.

The destination is a Path[T]; the value must match its target type by structure (Array[Image] and ImageSequence interchange, Image into a Thumbnail slot is rejected). The |= / &= operators lower path |= value (skip if exists) and path &= value (overwrite) to this node.

Attributes:

Name Type Description
destination Procedure[Path]

The Path position to store at.

value Procedure[CGType]

The procedure producing the value to store.

skip_if_exists Setting[bool]

If true, keep an existing stored value instead of re-running value and overwriting it.

Source code in capturegraph-lib/capturegraph/procedures/nodes/destination/cache.py
@make_procedure
class CacheProcedure[T: CGType](Procedure[T]):
    """Store ``value`` at ``destination`` and return the cached value.

    The destination is a ``Path[T]``; the value must match its target type by
    structure (``Array[Image]`` and ``ImageSequence`` interchange, ``Image`` into
    a ``Thumbnail`` slot is rejected). The ``|=`` / ``&=`` operators lower
    ``path |= value`` (skip if exists) and ``path &= value`` (overwrite) to this
    node.

    Attributes:
        destination: The ``Path`` position to store at.
        value: The procedure producing the value to store.
        skip_if_exists: If true, keep an existing stored value instead of
            re-running ``value`` and overwriting it.
    """

    destination: Procedure[Path]
    value: Procedure[CGType]
    skip_if_exists: Setting[bool] = False

    def _resolve_type(self) -> type[CGType]:
        """The stored value's type, checked against the destination position."""
        check_type(
            self.value.return_type,
            path_target(self.destination),
            "CacheProcedure value",
        )
        return self.value.return_type