Skip to content

[BE-07] Implement Redis caching via CacheModule for high-frequency read endpoints #265

Description

@Leothosine

Problem

@nestjs/cache-manager and cache-manager are listed in package.json but CacheModule is never configured in AppModule. Every request to dashboard stats, menu item listings, and public restaurant data hits PostgreSQL with a full query. As the number of restaurants and concurrent users grows, this creates unnecessary database load on data that changes infrequently.

Proposed Solution

  1. Configure CacheModule.registerAsync() in AppModule with a Redis store and env-configurable TTL (CACHE_TTL)
  2. Apply @UseInterceptors(CacheInterceptor) to:
    • GET /api/admin/dashboard (TTL: 60s)
    • Public menu listing endpoint (TTL: 300s)
    • Public restaurant info endpoint (TTL: 300s)
  3. Use @CacheKey() with restaurant-scoped keys: restaurant:{id}:resource
  4. Call cacheManager.del(key) in mutation service methods to invalidate on write

Acceptance Criteria

  • Second identical GET request does not generate a new database query (verified via TypeORM query logging)
  • Cache is invalidated after a menu item is created, updated, or deleted
  • Redis key naming follows the restaurant:{id}:resource convention
  • TTL configurable via CACHE_TTL env variable
  • Cache miss falls through to database transparently

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions