Function: TTL()

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

Defined in: src/data-management/cache/ttl.decorator.ts:78

Parameters

Parameter Type Description
ttl number Time-to-live en milisegundos

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>

TTL

IMPORTANTE: El método debe ser async o retornar una Promise.

Examples

// Cache en memoria (default) por 5 segundos
@TTL(5000)
async getStores() {
  return await fetch('/api/stores').then(r => r.json());
}
// Cache en localStorage por 1 hora
@Cache(LocalStorageCache)
@TTL(3600000)
async getUserPreferences() {
  return await fetch('/api/preferences').then(r => r.json());
}
// Cache con argumentos
@Cache(LocalStorageCache)
@TTL(5000)
async getUserById(id: string) {
  return await fetch(`/api/users/${id}`).then(r => r.json());
}