Skip to content
GitHub

ThemeCache

class in meocord/common Since 4.1.0

class ThemeCache

An 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

TypeScript
@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): void

Forgets a server's theme, so the next call from it looks it up again.

Parameters

NameTypeDescription
guildId?string

The server's id; without it, every server's theme is forgotten.

invalidateUser

invalidateUser(userId?: string): void

Forgets a user's theme, so the next call from them looks it up again.

Parameters

NameTypeDescription
userId?string

The user's id; without it, every user's theme is forgotten.