Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1kbgz Tributary Lazy Temporal Utils

From Leeroopedia
Knowledge Sources
Domains Lazy_Evaluation, Caching, Time_Series
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete time-based caching and windowing utilities for lazy evaluation nodes, provided by the Tributary library.

Description

The lazy temporal utils module provides three functions that extend lazy nodes with temporal caching and windowing behavior. Expire wraps a node's _call with temporalcache.expire, causing recomputation only when a specified time schedule expires (e.g., every hour, every Monday). Interval wraps with temporalcache.interval, causing recomputation on a fixed time interval (e.g., every 5 minutes). Window accumulates values into a list buffer of a given size, enabling sliding-window operations on lazy node outputs.

All three create derived nodes via _gennode and monkey-patch _call to inject the caching behavior. The functions are attached as methods on the Node class: Node.expire, Node.interval, Node.window.

Usage

Import these functions when you need time-based caching or windowing on lazy nodes. Use Expire for schedule-based recomputation (e.g., refresh data daily), Interval for fixed-interval recomputation (e.g., poll every 5 minutes), and Window for collecting sliding windows of values.

Code Reference

Source Location

Signature

def Expire(
    node, second=None, minute=None, hour=None, day=None,
    day_of_week=None, week=None, month=None, maxsize=128,
):
    """Recompute node only when the specified time schedule expires"""

def Interval(
    node, seconds=0, minutes=0, hours=0, days=0,
    weeks=0, months=0, years=0, maxsize=128,
):
    """Recompute node on a fixed time interval"""

def Window(node, size=-1, full_only=False):
    """Collect a window of values from the node

    Args:
        size (int): size of windows (-1 = unbounded)
        full_only (bool): only return if list is full
    """

Import

from tributary.lazy.utils import Expire, Interval, Window

I/O Contract

Inputs

Name Type Required Description
node Node Yes Input lazy node to wrap
second int No (Expire) Second schedule for expiration
minute int No (Expire) Minute schedule for expiration
hour int No (Expire) Hour schedule for expiration
day int No (Expire) Day schedule for expiration
day_of_week int No (Expire) Day of week schedule
week int No (Expire) Week schedule
month int No (Expire) Month schedule
seconds int No (Interval) Seconds between recomputations (default: 0)
minutes int No (Interval) Minutes between recomputations
hours int No (Interval) Hours between recomputations
days int No (Interval) Days between recomputations
weeks int No (Interval) Weeks between recomputations
months int No (Interval) Months between recomputations
years int No (Interval) Years between recomputations
maxsize int No Cache size (default: 128)
size int No (Window) Window size (-1 = unbounded, default: -1)
full_only bool No (Window) Only return if window is full (default: False)

Outputs

Name Type Description
return Node A new lazy node with temporal caching or windowing behavior applied

Usage Examples

Expire — Daily Recomputation

from tributary.lazy import Const
from tributary.lazy.utils import Expire

# A node that recomputes only once per day
data = Const(value=fetch_market_data())
cached = Expire(data, hour=9, minute=30)  # Recompute at 9:30 each day

print(cached())  # Uses cached value until 9:30 next day

Interval — Poll Every 5 Minutes

from tributary.lazy import Const
from tributary.lazy.utils import Interval

# A node that recomputes every 5 minutes
price = Const(value=get_price())
cached = Interval(price, minutes=5)

print(cached())  # Cached for 5 minutes, then recomputes

Window — Sliding Window of Values

from tributary.lazy import Const
from tributary.lazy.utils import Window

# Collect a window of 3 values
source = Const(value=1)
windowed = Window(source, size=3, full_only=True)

# On first 3 evaluations, returns the accumulated list
# After 3 values: [1, 1, 1]
print(windowed())

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment