| import type Keyv from 'keyv'; |
| import { isLeader } from '~/cluster'; |
|
|
| |
| |
| |
| |
| |
| export abstract class BaseRegistryCache { |
| protected readonly PREFIX = 'MCP::ServersRegistry'; |
| protected abstract readonly cache: Keyv; |
|
|
| protected async leaderCheck(action: string): Promise<void> { |
| if (!(await isLeader())) throw new Error(`Only leader can ${action}.`); |
| } |
|
|
| protected successCheck(action: string, success: boolean): true { |
| if (!success) throw new Error(`Failed to ${action} in cache.`); |
| return true; |
| } |
|
|
| public async reset(): Promise<void> { |
| await this.leaderCheck(`reset ${this.cache.namespace} cache`); |
| await this.cache.clear(); |
| } |
| } |
|
|