Unified social media embed caching singleton that provides a three-tier cache hierarchy (memory → server → direct fetch) for Reddit and Twitter embed clients, with request deduplication and async background refresh. ## Key Components - **`SocialEmbedCache`** — Singleton class exposing all cache operations - **`CacheOptions`** — Interface defining `platform`, `url`, and `apiEndpoint` per-call inputs - **`getFromMemory / setInMemory`** — In-process `Map`-backed cache layer - **`getFromServer`** — Checks the server-side cache via `?cache-only=true` query param - **`setInServer`** — Writes data to the server cache with promise-level deduplication via `cachingRequests` - **`fetchWithHierarchy`** — Orchestrates the full lookup chain: memory → server cache → Reddit direct browser fetch → server proxy fallback - **`scheduleAsyncRefresh`** — Fires a background refresh 1 second after load to keep the server cache warm without blocking the consumer - **`fetchDirect`** — Thin wrapper around a caller-supplied `directFetcher` function with uniform logging ## Usage Example ```typescript import { SocialEmbedCache } from './social-embed-cache'; const cache = SocialEmbedCache.getInstance(); await cache.fetchWithHierarchy({ platform: 'reddit', url: 'https://www.reddit.com/r/example/comments/abc123/.json', apiEndpoint: '/content/api/blog/reddit-proxy', dataValidator: (data) => Array.isArray(data) && data.length > 0, onDataUpdate: (data) => setEmbedData(data), onError: (msg) => setError(msg), onLoading: (loading) => setLoading(loading), }); ``` > **Note:** Pass `apiEndpoint` on each call to route through your own reverse proxy rather than a hard-coded hub path. The singleton is pure TypeScript with no React dependency, making it safe to share across any embed satellite. ## Source [`social-embed-cache.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/social-embed-cache.ts)