Skip to content

Feat: cache GitHub team list (24 h) with --no-cache option #18

Description

@shouze

Motivation

fetchRepoTeams can fire dozens of GitHub API requests on every run (one page per team × N teams). The team list is quasi-static (changes rarely). Caching it for 24 h eliminates those calls on repeated runs.

Changes planned

  • Create src/cache.ts with pure helpers:
    • getCacheDir(): string — OS-aware cache directory (macOS: ~/Library/Caches/github-code-search, Linux: $XDG_CACHE_HOME/github-code-search or ~/.cache/github-code-search)
    • getCacheKey(org, prefixes): string — deterministic file name (org + sorted prefixes)
    • readCache<T>(key): T | null — returns null if file missing, unreadable, or older than 24 h (based on mtime)
    • writeCache<T>(key, data): void — creates directory if absent, writes JSON
    • CACHE_TTL_MS = 24 * 60 * 60 * 1000 exported constant
  • Create src/cache.test.ts (TTL expiry, deterministic key, missing directory)
  • Update fetchRepoTeams(org, token, prefixes, useCache?) in src/api.ts to read/write cache
  • Add --no-cache flag to addSearchOptions in github-code-search.ts; print a dim message on stderr when cached data is used
  • Update README.md: add Cache section with cache location per OS and purge commands

Cache location

OS Path
macOS ~/Library/Caches/github-code-search/
Linux $XDG_CACHE_HOME/github-code-search/ or ~/.cache/github-code-search/

Purge commands

# macOS
rm -rf ~/Library/Caches/github-code-search

# Linux
rm -rf ${XDG_CACHE_HOME:-~/.cache}/github-code-search

Acceptance criteria

  • bun test — all tests green
  • bun run lint — zero oxlint errors
  • bun run format:check — zero diff
  • bun run knip — no unused exports
  • bun run build.ts — binary compiles

Dependencies

Depends on #17 (src/api-utils.ts must be merged first).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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