Skip to main content

Caching

Complete Example

Runtime And Lifecycle Notes

  • Cache(undefined) removes the key unless negative caching is configured.
  • Cache#setExpire(seconds) uses seconds.
  • defineCache typed placeholders support string, number, and boolean.
  • RedisCache.loadCache() returns read, write, remove, has, and multi.
  • RedisCache.removeTag(tag) removes tagged cache entries.
  • fieldable caches use Redis hashes and cannot combine with stale or negative cache options.
  • Scheduler.add() supports cron strings and { delay }.
  • Scheduler.load() reads default exports from *.schedule.* files produced by defineJob().
  • scanDirectory() matches .ts, .js, .tsx, .jsx, and .mjs.

Anti-Patterns

  • Returning raw values from defineCache handlers instead of new Cache(value).
  • Treating cache as source of truth.
  • Forgetting to destroy manually created Redis or TypeORM clients.
  • Scheduling jobs without idempotency when side effects can repeat.