Skip to content

feat: add local file-based eligibility cache with --refresh flag - #20

Merged
aaearon merged 2 commits into
mainfrom
feat/eligibility-cache
Feb 19, 2026
Merged

feat: add local file-based eligibility cache with --refresh flag#20
aaearon merged 2 commits into
mainfrom
feat/eligibility-cache

Conversation

@aaearon

@aaearon aaearon commented Feb 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a local file-based eligibility cache (~/.grant/cache/) that stores API responses as JSON files with a 4-hour default TTL, avoiding redundant API roundtrips on subsequent runs
  • Introduces --refresh flag on grant and grant env to bypass the cache and fetch fresh eligibility data
  • Adds cache_ttl config option in ~/.grant/config.yaml for customizing the TTL (Go duration syntax, e.g. 2h, 30m)

Details

  • Generic cache.Store with Get[T]/Set[T] functions and injectable clock for testing
  • CachedEligibilityLister decorator wraps both cloud and groups eligibility listers, implementing the existing interfaces transparently
  • buildCachedLister() factory in cmd/root.go shared by root and env commands
  • Cache failures (read/write) silently fall through to the live API — no user-visible errors
  • Cache is keyed per CSP (e.g. eligibility_azure.json, eligibility_aws.json)

Test plan

  • Unit tests for cache.Store (hit, miss, expiry, invalidation, corrupt data)
  • Unit tests for CachedEligibilityLister (cache hit skips API, cache miss calls API and writes, refresh bypasses read, groups eligibility caching)
  • Unit tests for config.ParseCacheTTL (default, custom, invalid)
  • Flag registration tests for --refresh on root and env commands
  • make test passes

Cache eligibility API responses in ~/.grant/cache/ to skip the API
roundtrip on subsequent runs. Default TTL is 4 hours, configurable
via cache_ttl in ~/.grant/config.yaml.

- internal/cache: generic Store with Get/Set/Invalidate and TTL expiry
- internal/cache: CachedEligibilityLister decorator for both cloud and
  groups eligibility interfaces with verbose logging on hit/miss/refresh
- --refresh flag on grant and grant env to bypass cache
- cache_ttl config option with ParseCacheTTL helper
- groups model types added as prerequisite for cache interface
@aaearon
aaearon force-pushed the feat/eligibility-cache branch from 88754a2 to 01f233e Compare February 19, 2026 14:57
@aaearon
aaearon merged commit 85c0936 into main Feb 19, 2026
1 check passed
@aaearon
aaearon deleted the feat/eligibility-cache branch February 19, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant