Skip to content

CacheManager

Defined in: utils/CacheManager.ts:31

Provides a structured, namespace-aware layer on top of a BaseCacheAdapter. Set on the Hono context by Honocord after calling withCache() and accessible in middleware and handlers as c.var.cache, or via interaction.fetcher.

const cache = c.var.cache; // CacheManager | null

new CacheManager(adapter, defaultTtlMs?): CacheManager

Defined in: utils/CacheManager.ts:50

BaseCacheAdapter

The cache backend to use

number = ...

Fallback TTL in milliseconds for all set/mset calls that don’t supply their own TTL. Defaults to 5 minutes.

CacheManager

readonly channels: NamespaceAccessor<CachedChannel>

Defined in: utils/CacheManager.ts:36

Cached channel objects. Note: channels resolved from raw interaction payloads are not populated here automatically — Discord only provides partial objects (id + type) in those cases.


readonly guilds: NamespaceAccessor<APIGuild>

Defined in: utils/CacheManager.ts:42

Cached guild objects. Not populated automatically — the guild object on interactions is partial and only carries id, features, and locale.


readonly members: MemberNamespaceAccessor

Defined in: utils/CacheManager.ts:44

Cached guild member objects, scoped by guildId. Members resolved from interaction data are populated automatically.


readonly roles: NamespaceAccessor<APIRole>

Defined in: utils/CacheManager.ts:38

Cached role objects. Roles resolved from interaction data are populated automatically.


readonly users: NamespaceAccessor<APIUser>

Defined in: utils/CacheManager.ts:40

Cached user objects. Users found in interaction resolved data and interaction.user/interaction.member.user are populated automatically.

getDMChannel(userId): Promise<CachedDMChannel | undefined>

Defined in: utils/CacheManager.ts:129

Fetches a cached DM channel for a user.

Unlike other namespace accessors, DM channels are looked up by user ID rather than channel ID — use this instead of channels.get when you only have the user ID.

string

Promise<CachedDMChannel | undefined>


getGuildRoles(guildId): Promise<APIRole[]>

Defined in: utils/CacheManager.ts:103

Returns all cached roles for the given guild.

Reads a stored index of role IDs and resolves each one from the role namespace. Returns an empty array if none are cached.

string

Promise<APIRole[]>


populate(i): Promise<void>

Defined in: utils/CacheManager.ts:157

Extracts and caches users, roles, members, and channels from a raw interaction payload. Called automatically by Honocord before dispatching to handlers when a cache adapter is registered.

ValidInteraction

Promise<void>


setDMChannel(userId, channel, ttlMs?): Promise<void>

Defined in: utils/CacheManager.ts:148

Manually caches a DM channel for a user. Useful if you have a DM channel object from another source and want to store it in the cache.

DM channels are stored in two places: the dm-channel namespace keyed by user ID, and the channel namespace keyed by channel ID. Both must be populated for the cache to function properly — this method handles both automatically.

string

CachedChannel

number

Promise<void>


setGuildRoles(guildId, roles): Promise<void>

Defined in: utils/CacheManager.ts:114

Caches all roles for a guild, and stores an index of their IDs so getGuildRoles can look them back up later.

string

APIRole[]

Promise<void>