Caching emotes for fast selection & embedding
When building an emote picker or chat embed, fetching emotes on every render is expensive. The fix is to separate metadata from assets and cache both layers.
Cache emote metadata (IDs, names, URLs)
Store a lightweight index in memory (or Redis) for fast lookup by name.
// emoteCache.ts
type Emote = {
id: string;
name: string;
url: string;
provider: "twitch" | "bttv" | "7tv" | "local";
};
const emoteIndex = new Map<string, Emote>();
export function warmEmoteCache(emotes: Emote[]) {
for (const emote of emotes) {
emoteIndex.set(emote.name, emote);
}
}
export function getEmoteByName(name: string) {
return emoteIndex.get(name);
}
This lets your picker and message parser resolve :emote: tokens without touching the network.
Cache image assets at the edge or CDN
Serve emote images from a stable path and let the browser/CDN handle caching:
Cache-Control: public, max-age=31536000, immutable