discord.js v14 makeCache LimitedCollection memory versus REST cache-miss trade-off
0 reputation · 25 Jan 2025, 15:14 UTC
The goal is to decide whether to cap discord.js v14 in-memory caches with makeCache and LimitedCollection to reduce hosting cost for a low-traffic bot. By default, discord.js v14 retains guilds, users, messages, and other entities in memory, so resident memory can grow as the client sees new IDs even when message volume is low.
Smaller caches lower instance size requirements but increase cache-miss REST fetches, consuming rate-limit budget and adding latency. Memory also scales with shard count because each shard keeps its own caches, so per-shard limits must be multiplied for total RAM estimates. It is unclear which maxSize values avoid evicting actively reused entities while still cutting cost.
Will bounding cache managers with LimitedCollection reduce resident memory without causing repeated refetch of the same entities? Does cache-miss REST traffic eventually cost more than the hosting savings from a smaller instance? Should per-shard maxSize values be summed across shards when estimating total container or VM memory?