Principle:1kbgz Tributary Temporal Caching
| Knowledge Sources | |
|---|---|
| Domains | Caching, Time_Series, Lazy_Evaluation |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
A time-based caching strategy for lazy evaluation nodes that defers recomputation until a time schedule expires or a fixed interval elapses, combined with sliding-window accumulation of values.
Description
Temporal caching extends standard memoization (which caches based on input equality) with time-based invalidation. In data streaming and financial applications, source data may change at known time intervals (e.g., market data refreshes every minute, daily reports update at market open). Temporal caching avoids unnecessary recomputation by caching results and only invalidating the cache when the time schedule dictates.
There are two scheduling models:
- Expire: Schedule-based invalidation using calendar fields (second, minute, hour, day, day_of_week, week, month). The cache recomputes only when the specified time schedule expires. For example, "recompute at 9:30 every weekday" uses Expire.
- Interval: Fixed-duration invalidation using relative time deltas (seconds, minutes, hours, days, weeks, months, years). The cache recomputes after the specified duration elapses. For example, "recompute every 5 minutes" uses Interval.
Additionally, Window provides temporal accumulation: instead of caching a single value, it collects a sliding window of recent values into a list buffer, enabling operations like moving averages and rolling statistics.
Usage
Use this principle when designing lazy evaluation systems that need time-based cache invalidation. It is appropriate when:
- Source data updates at known time schedules (market hours, daily reports)
- Recomputation is expensive and should be avoided between updates
- Sliding-window aggregates are needed over a stream of values
- The system is built on lazy (pull-based) evaluation nodes
Theoretical Basis
Temporal caching combines memoization with time-based cache invalidation:
# Abstract algorithm description (NOT real implementation)
# Expire: recompute when calendar schedule triggers
def expire_cache(compute, schedule):
cached_value = None
last_compute_time = None
def wrapper(*args):
nonlocal cached_value, last_compute_time
if schedule_expired(last_compute_time, schedule):
cached_value = compute(*args)
last_compute_time = now()
return cached_value
return wrapper
# Interval: recompute after fixed duration
def interval_cache(compute, seconds):
cached_value = None
last_compute_time = None
def wrapper(*args):
nonlocal cached_value, last_compute_time
if last_compute_time is None or (now() - last_compute_time) >= seconds:
cached_value = compute(*args)
last_compute_time = now()
return cached_value
return wrapper
# Window: accumulate sliding window of values
def window(size, full_only):
buffer = []
def wrapper(data):
buffer.append(data)
if size > 0:
buffer = buffer[-size:]
if full_only and len(buffer) < size:
return None
return buffer
return wrapper
The temporalcache library provides the expire and interval decorators, which Tributary integrates by monkey-patching the node's _call method.