@elgato/streamdeck
Version:
The official Node.js SDK for creating Stream Deck plugins.
38 lines (37 loc) • 1.08 kB
JavaScript
/**
* Provides a cache for action settings, keyed by action instance identifier.
*/
class SettingsCache {
/**
* Underlying map of action ID to cached settings.
*/
#entries = new Map();
/**
* Removes the cached settings for the specified action.
* @param id Action instance identifier.
*/
delete(id) {
this.#entries.delete(id);
}
/**
* Gets the cached settings for the specified action.
* @param id Action instance identifier.
* @returns The cached settings when present; otherwise `undefined`.
*/
get(id) {
const settings = this.#entries.get(id);
return settings !== undefined ? structuredClone(settings) : undefined;
}
/**
* Sets the cached settings for the specified action.
* @param id Action instance identifier.
* @param settings The settings to cache.
*/
set(id, settings) {
this.#entries.set(id, structuredClone(settings));
}
}
/**
* Singleton instance of the settings cache.
*/
export const settingsCache = new SettingsCache();