Skip to content

memo

memo #

What the store has for one call key: its sealed results, a claim to compute it, or nothing.

Scratch.memo(key) is the one question a memoized call asks, answered in that order:

  1. Results — a hold on every sealed result, in return order. A ragged set, one result of two evicted, is no result at all.
  2. Computing — nobody has sealed it, but some living thread or process holds the key's call lock: the body is running right now.
  3. Nothing — neither: nobody has computed this key and nobody is.

Memo dataclass #

What the store has for one call key; see the module for the three answers.

Attributes:

Name Type Description
results tuple[Pinned, ...]

A hold on each sealed result, in return order; empty unless every one of them is present.

computing bool

Whether the key's call lock is held, so its body is running somewhere; False whenever results is not empty.

Source code in capturegraph-lib/capturegraph/scratch/store/memo.py
@dataclass(frozen=True, slots=True)
class Memo:
    """What the store has for one call key; see the module for the three answers.

    Attributes:
        results: A hold on each sealed result, in return order; empty unless
            every one of them is present.
        computing: Whether the key's call lock is held, so its body is running
            somewhere; ``False`` whenever ``results`` is not empty.
    """

    results: tuple[Pinned, ...]
    computing: bool

call_memo(scratch, key, count) #

What scratch has for key, whose call returns count results.

Source code in capturegraph-lib/capturegraph/scratch/store/memo.py
def call_memo(scratch: Scratch, key: CallKey, count: int) -> Memo:
    """What ``scratch`` has for ``key``, whose call returns ``count`` results."""
    held = lookup_call(scratch, key, count)
    if held is not None:
        return Memo(tuple(held), False)
    return Memo((), not lock_is_free(scratch.call_locks_dir / lock_file_name(key.hex)))