Skip to content

Caching & Structures

Lunibee manages Discord resources (Users, Guilds, Channels, Roles, Messages) using Canonical Identity Caching.

When a resource is received via Gateway event or fetched via REST, the resource manager checks if an existing instance already exists in memory.

If it exists, Lunibee mutates the existing structure in place and returns the same object reference. This prevents subtle desynchronization bugs where two parts of your application hold different versions of the same guild or user.

const userA = client.users.cache.get("123456789012345678");
const userB = await client.users.fetch("123456789012345678");
console.log(userA === userB); // true! Exact same instance

lunibee (collection) provides a high-performance Cache with optional bounds and Time-To-Live (TTL):

import { Cache } from "lunibee";
const messageCache = new Cache<string, Message>({
maxSize: 1000, // Keeps memory predictable
ttl: 60 * 1000, // Evicts unreferenced entries after 60s
});

Structures like Message, Guild, and Channel expose intuitive helper methods that automatically route through the manager’s REST client:

client.on("messageCreate", async (message) => {
// Directly edit the message
await message.edit({ content: "Updated content!" });
// Or delete it
await message.delete();
});