Function: CacheTags()

function CacheTags(extractor: TagExtractor): (target: any, context: ClassMethodDecoratorContext) => void;

Defined in: src/data-management/cache/cache-tags.decorator.ts:56

Parameters

Parameter Type Description
extractor TagExtractor Función que extrae tags del resultado/args

Returns

(target: any, context: ClassMethodDecoratorContext): void;

Parameters

Parameter Type
target any
context ClassMethodDecoratorContext

Returns

void

Cache Tags

Los tags permiten invalidar selectivamente entries relacionadas sin necesitar eventos o regenerar cache keys.

Examples

// Tag basado en el resultado
@CacheTags((result) => [`product:${result.id}`])
async getProduct(id: string) { }
// Tag basado en argumentos
@CacheTags((_, args) => [`product:${args[0]}`])
async getProduct(id: string) { }
// Múltiples tags
@CacheTags((result) => [
  `product:${result.id}`,
  `category:${result.category}`,
  `brand:${result.brand}`
])
async getProduct(id: string) { }
// Tags de array de resultados
@CacheTags((result) => result.map(p => `product:${p.id}`))
async getProducts() { }
// Invalidar por tag
await productService.updateProduct(id, data);
cache.invalidateTag(`product:${id}`);