UNPKG

@backstage/backend-defaults

Version:

Backend defaults used by Backstage backend apps

118 lines (113 loc) 4.17 kB
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api'; import { LoggerService, RootConfigService, CacheService } from '@backstage/backend-plugin-api'; /** * Key-value store for caching data. * * See {@link @backstage/code-plugin-api#CacheService} * and {@link https://backstage.io/docs/backend-system/core-services/cache | the service docs} * for more information. * * @public */ declare const cacheServiceFactory: _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.CacheService, "plugin", "singleton">; /** * Options given when constructing a {@link CacheManager}. * * @public */ type CacheManagerOptions = { /** * An optional logger for use by the PluginCacheManager. */ logger?: LoggerService; /** * An optional handler for connection errors emitted from the underlying data * store. */ onError?: (err: Error) => void; }; /** * Implements a Cache Manager which will automatically create new cache clients * for plugins when requested. All requested cache clients are created with the * connection details provided. * * @public */ declare class CacheManager { /** * Keys represent supported `backend.cache.store` values, mapped to factories * that return Keyv instances appropriate to the store. */ private readonly storeFactories; private readonly logger?; private readonly store; private readonly connection; private readonly errorHandler; private readonly defaultTtl?; private readonly storeOptions?; /** * Creates a new {@link CacheManager} instance by reading from the `backend` * config section, specifically the `.cache` key. * * @param config - The loaded application configuration. * @param options - Optional configuration for the CacheManager. * @returns A new CacheManager instance. */ static fromConfig(config: RootConfigService, options?: CacheManagerOptions): CacheManager; /** * Parse store-specific options from configuration. * * @param store - The cache store type ('redis', 'valkey', 'memcache', 'infinispan', or 'memory') * @param config - The configuration service * @param logger - Optional logger for warnings * @returns The parsed store options */ private static parseStoreOptions; /** * Parse Redis-specific options from configuration. */ private static parseRedisOptions; /** * Parse Valkey-specific options from configuration. */ private static parseValkeyOptions; /** * Construct the full namespace based on the options and pluginId. * * @param pluginId - The plugin ID to namespace * @param storeOptions - Optional cache store configuration options * @returns The constructed namespace string combining the configured namespace with pluginId */ private static constructNamespace; /** * Generates a PluginCacheManager for consumption by plugins. * * @param pluginId - The plugin that the cache manager should be created for. * Plugin names should be unique. */ forPlugin(pluginId: string): CacheService; private getClientWithTtl; private createRedisStoreFactory; private createValkeyStoreFactory; private createMemcacheStoreFactory; private createMemoryStoreFactory; private createInfinispanStoreFactory; /** * Creates an Infinispan client using dynamic import (production use). * @returns Promise that resolves to an Infinispan client */ private createInfinispanClientAsync; /** * Creates an Infinispan client using synchronous import (testing purposes). * @returns Promise that resolves to an Infinispan client */ private createInfinispanClientSync; /** * Creates an Infinispan client based on the provided configuration. * @param useSync - Whether to use synchronous import (for testing) or dynamic import * @returns Promise that resolves to an Infinispan client */ private createInfinispanClient; } export { CacheManager, cacheServiceFactory }; export type { CacheManagerOptions };