Function: CacheInvalidate()

function CacheInvalidate(ProviderClass: Constructor<CacheProvider>, tagExtractor: TagExtractor): (originalMethod: Function, context: ClassMethodDecoratorContext) => (this: any, ...args: any[]) => Promise<any>;

Defined in: src/data-management/cache/cache-invalidate.decorator.ts:37

Parameters

Parameter Type Description
ProviderClass Constructor<CacheProvider> La clase del cache provider a usar
tagExtractor TagExtractor Función que extrae tags del resultado y argumentos

Returns

(originalMethod: Function, context: ClassMethodDecoratorContext): (this: any, ...args: any[]) => Promise<any>;

Parameters

Parameter Type
originalMethod Function
context ClassMethodDecoratorContext

Returns

(this: any, ...args: any[]): Promise<any>;

Parameters

Parameter Type
this any
args any[]

Returns

Promise<any>

Cache Invalidate

Decorator

Invalida (elimina) las entradas del cache que coincidan con los tags extraídos del resultado de un método. Útil para limpiar el cache después de operaciones de escritura que afectan a múltiples entradas relacionadas.

Examples

@CacheInvalidate(
  LocalStorageCache,
  (result) => ['users-list', `org:${result.organizationId}`]
)
async deleteUser(userId: string): Promise<void> {
  await this.httpClient.delete(`/users/${userId}`);
}
Combinar con

Cache Update

@CacheUpdate(LocalStorageCache, (result) => [`user:${result.id}`])
@CacheInvalidate(LocalStorageCache, (result) => ['users-list', `org:${result.organizationId}`])
async updateUser(id: string, data: any): Promise<User> {
  const response = await this.httpClient.put(`/users/${id}`, data);
  return response.data;
}