Skip to content

feat(api): add caching for GET endpointsΒ #6

@perzeuss

Description

@perzeuss

🚦 Implement Caching for Todos API Responses (Including Search Queries)

πŸ“‹ Overview

The todos API currently performs a (fake) database read for every request, including when fetching or searching todos. Add an API response caching layer to reduce latency and database load, and to improve user experience for repeated queries. Caching must include responses for list and search queries.


🎯 Acceptance Criteria

  • API GET responses for /api/todos and /api/todos?search=... are cached
  • Search query results (with parameters) have separate cache entries per unique query string
  • Configurable cache expiration (TTL) is respected (default: 60s)
  • Solution works locally and is pluggable for future production Redis/memory cache (start with in-memory)
  • No caching for non-GET endpoints

Nice to Have

  • Cache is properly invalidated or updated when a todo is created, updated, toggled, or deleted (not strictly required, but improves data accuracy)
  • No stale or incorrect data is served after mutations

πŸ”§ Technical Requirements

  • Use a caching solution such as node-cache, lru-cache, or a tool like Redis (integration optional for now)
  • Key cache by endpoint and query string, e.g. /api/todos?search=foo
    • Trim and encode user input to create the cache key
  • Set TTL for cache entries (configurable in env or code)
  • No caching for POST/PUT/PATCH/DELETE responses

🚫 Out of Scope

  • Do not implement distributed or cloud cache (start with local memory)
  • No user-level or per-session customizations for caching
  • Cache update/invalidation after data mutations is optional

βœ… Getting Started

  1. Install a small caching library:
    npm install node-cache
  2. Implement cache-lookup logic in the relevant API route handlers before database queries.
  3. Cache should key responses by both URL and query parameters.
  4. (Nice to have) On POST/PUT/PATCH/DELETE to todos, invalidate or update affected cache keys.
  5. Make cache TTL easily configurable.

πŸ“š Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions