Manager.OzCache.OzCache

class Manager.OzCache.OzCache

Generic redis-backed rolling cache for outgoing device payloads.

Construction is cheap; actual Redis connect happens in configure(). Safe to leave unconfigured (all methods become no-ops).

_key() str
bulk_load(payloads: List[dict]) int

Insert multiple payloads in one pipeline. Caller is responsible for ordering — LPUSH-ing oldest-first keeps the newest entry at list head.

clear() None

Drop the entire cache for this device (test/recovery helper).

configure(config: dict, device_id: str, publish_interval_sec: int, host: str | None = None, port: int | None = None) bool

Wire up from the device config. Returns True if the cache is active. A disabled flag, missing device_id, missing redis package, or a failed connect all return False and leave the instance in no-op mode.

push(payload: dict) bool

Append one outgoing payload to the head of the list.

refill(manager, hours: int | None = None) int

One-shot refill from ppbanalytics. Returns the number of payloads loaded. Caller controls retry — see start_background_refill.

size() int
window() List[dict]

Return every cached payload, newest first.

_client = None
_push_count = 0
capacity = 0
property client

Public handle to the underlying redis client.

Other consumers (e.g. the Anomaly Scheduler) reuse this connection for their own keys instead of opening a second one.

device_id = ''
enabled = False
hours = 48
prefix = 'cache'