ThemeCache
class in meocord/common Since 4.1.0
class ThemeCacheAn app's cache of the themes @MeoCord({ themeFor }) looked up, by server and by user.
Inject it to clear a result once the theme it came from changes, so the next call looks it up again rather than waiting for the result to expire. Each app has its own.
Examples
@Service()
export class GuildSettings {
readonly themes = new Map<string, ThemeOverride>()
constructor(private readonly cache: ThemeCache) {}
setColour(guildId: string, primary: HexColorString) {
this.themes.set(guildId, { colors: { primary } })
// The next call in this server looks its theme up again, rather than waiting for ttlSeconds
this.cache.invalidateGuild(guildId)
}
}Members
constructor
new ThemeCache()invalidateGuild
invalidateGuild(guildId?: string): voidForgets a server's theme, so the next call from it looks it up again.
Parameters
| Name | Type | Description |
|---|---|---|
guildId? | string | The server's id; without it, every server's theme is forgotten. |
invalidateUser
invalidateUser(userId?: string): voidForgets a user's theme, so the next call from them looks it up again.
Parameters
| Name | Type | Description |
|---|---|---|
userId? | string | The user's id; without it, every user's theme is forgotten. |