Skip to main content

Caching & Retry

PrismNetwork provides two complementary resilience layers: an actor-based response cache with LRU eviction and TTL, and pluggable retry policies for automatic request retries.

Response Cache

PrismResponseCache

An actor-isolated LRU cache that stores response data with time-to-live:
Basic Cache Usage

Cache Policies

PrismCachePolicy controls how requests interact with the cache layer:
Using Cache Policies

Cache Entry

Each PrismCacheEntry tracks its creation time and TTL:
Cache Entry Properties
The LRU cache automatically evicts the least recently accessed entries when the cache exceeds maxSize. Expired entries are also cleaned up on access.

Retry Policies

PrismRetryPolicy Protocol

Implement this protocol to define custom retry logic:
Protocol Definition

Exponential Backoff

PrismExponentialBackoff increases the delay exponentially with random jitter to prevent thundering herd:
Exponential Backoff
The delay formula is: min(baseDelay × 2^attempt + jitter, maxDelay) where jitter is a random value between 0 and 0.5 seconds.

Linear Retry

PrismLinearRetry uses a constant delay between attempts:
Linear Retry

Custom Retry Policy

Implement the protocol for fine-grained control:
Custom Policy

Combining Cache + Retry

Use both layers together for resilient networking:
Resilient Network Layer

Next Steps

Advanced Features

Request deduplication, offline queues, multipart uploads, and GraphQL.

WebSocket Client

Real-time communication with the WebSocket client.