CacheManager
Class: CacheManager
Section titled “Class: 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.
Example
Section titled “Example”const cache = c.var.cache; // CacheManager | nullConstructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CacheManager(
adapter,defaultTtlMs?):CacheManager
Defined in: utils/CacheManager.ts:50
Parameters
Section titled “Parameters”adapter
Section titled “adapter”BaseCacheAdapter
The cache backend to use
defaultTtlMs?
Section titled “defaultTtlMs?”number = ...
Fallback TTL in milliseconds for all set/mset calls that don’t supply their own TTL. Defaults to 5 minutes.
Returns
Section titled “Returns”CacheManager
Properties
Section titled “Properties”channels
Section titled “channels”
readonlychannels: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.
guilds
Section titled “guilds”
readonlyguilds: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.
members
Section titled “members”
readonlymembers:MemberNamespaceAccessor
Defined in: utils/CacheManager.ts:44
Cached guild member objects, scoped by guildId. Members resolved from interaction data are populated automatically.
readonlyroles:NamespaceAccessor<APIRole>
Defined in: utils/CacheManager.ts:38
Cached role objects. Roles resolved from interaction data are populated automatically.
readonlyusers: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.
Methods
Section titled “Methods”getDMChannel()
Section titled “getDMChannel()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<CachedDMChannel | undefined>
getGuildRoles()
Section titled “getGuildRoles()”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.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Returns
Section titled “Returns”Promise<APIRole[]>
populate()
Section titled “populate()”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.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
setDMChannel()
Section titled “setDMChannel()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
channel
Section titled “channel”ttlMs?
Section titled “ttlMs?”number
Returns
Section titled “Returns”Promise<void>
setGuildRoles()
Section titled “setGuildRoles()”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.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
APIRole[]
Returns
Section titled “Returns”Promise<void>
