refactor: remove inline cache types
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-defaults': patch
|
||||
---
|
||||
|
||||
Refactor cache manager inline types.
|
||||
@@ -11,15 +11,10 @@ import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public
|
||||
export class CacheManager {
|
||||
forPlugin(pluginId: string): {
|
||||
getClient(options?: CacheServiceOptions): CacheService;
|
||||
};
|
||||
forPlugin(pluginId: string): PluginCacheManager;
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options?: {
|
||||
logger?: LoggerService;
|
||||
onError?: (err: Error) => void;
|
||||
},
|
||||
options?: CacheManagerOptions,
|
||||
): CacheManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,24 +15,16 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
CacheService,
|
||||
CacheServiceOptions,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import Keyv from 'keyv';
|
||||
import { DefaultCacheClient } from './CacheClient';
|
||||
import { CacheManagerOptions } from './types';
|
||||
import { CacheManagerOptions, PluginCacheManager } from './types';
|
||||
|
||||
type StoreFactory = (pluginId: string, defaultTtl: number | undefined) => Keyv;
|
||||
|
||||
/*
|
||||
* TODO(freben): This class intentionally inlines the CacheManagerOptions and
|
||||
* PluginCacheManager types, to not break the api reports in backend-common
|
||||
* which re-exports it. When backend-common is deprecated, we can stop inlining
|
||||
* those types.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements a Cache Manager which will automatically create new cache clients
|
||||
* for plugins when requested. All requested cache clients are created with the
|
||||
@@ -66,18 +58,7 @@ export class CacheManager {
|
||||
*/
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options: {
|
||||
/**
|
||||
* 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;
|
||||
} = {},
|
||||
options: CacheManagerOptions = {},
|
||||
): CacheManager {
|
||||
// If no `backend.cache` config is provided, instantiate the CacheManager
|
||||
// with an in-memory cache client.
|
||||
@@ -126,9 +107,7 @@ export class CacheManager {
|
||||
* @param pluginId - The plugin that the cache manager should be created for.
|
||||
* Plugin names should be unique.
|
||||
*/
|
||||
forPlugin(pluginId: string): {
|
||||
getClient(options?: CacheServiceOptions): CacheService;
|
||||
} {
|
||||
forPlugin(pluginId: string): PluginCacheManager {
|
||||
return {
|
||||
getClient: (defaultOptions = {}) => {
|
||||
const clientFactory = (options: CacheServiceOptions) => {
|
||||
|
||||
Reference in New Issue
Block a user