Skip to content

feat: added local caching for category discovery (offline fallback support)

Bhaskar Battula requested to merge cache-support into develop

Description

This MR introduces a local caching mechanism for category discovery data in the CLI to improve reliability and usability when the API is unavailable or the user is offline.


What this MR does

  • Adds a local cache for category data after a successful API fetch
  • Implements fallback logic:
    • CLI first attempts to fetch categories from the API
    • If the API call fails, cached data is used (if available)
  • Displays a clear message when cached data is being used
  • Stores cache with basic metadata (e.g., fetched_at, environment scoping if applicable)
  • Ensures cache is scoped correctly to avoid cross-environment conflicts

Behavior Changes

  • corpus-client categories
    • Uses live API data when available
    • Falls back to cached data on failure
    • Outputs a message such as: "Using cached category data" when applicable

Tests Covered

  • Cache file is created after a successful API fetch
  • Cached data is reused when API is unavailable
  • Proper fallback behavior when API fails
  • Error handling when no cache exists and API is unreachable
  • CLI messaging clearly indicates cache vs live data

Closes

Closes: #23 (closed)

Merge request reports

Loading