Files
SimpleCloudNotifier/webapp/src/app/core/services/client-cache.service.ts
T
Mikescher 9352ff5c2c
Build Docker and Deploy / Build Docker Container (push) Successful in 51s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 7m29s
Build Docker and Deploy / Deploy to Server (push) Successful in 7s
UI improvements
2026-01-19 19:19:43 +01:00

42 lines
1.1 KiB
TypeScript

import { Injectable, inject } from '@angular/core';
import { Observable, of, catchError, map, shareReplay } from 'rxjs';
import { ApiService } from './api.service';
import { ClientPreview, UserPreview } from '../models';
export interface ResolvedClient {
clientId: string;
clientName: string | null;
userId: string;
userName: string | null;
agentModel: string;
agentVersion: string;
}
@Injectable({
providedIn: 'root'
})
export class ClientCacheService {
private apiService = inject(ApiService);
private cache = new Map<string, Observable<{client: ClientPreview, user: UserPreview} | null>>();
resolveClient(clientId: string): Observable<{client: ClientPreview, user: UserPreview} | null> {
if (!this.cache.has(clientId)) {
const request$ = this.apiService.getClientPreview(clientId).pipe(
map(response => ({
client: response.client,
user: response.user
})),
catchError(() => of(null)),
shareReplay(1)
);
this.cache.set(clientId, request$);
}
return this.cache.get(clientId)!;
}
clearCache(): void {
this.cache.clear();
}
}