Skip to content

Add opt-in response caching with --cache-ttl and a cache command#288

Open
jongio wants to merge 1 commit into
mainfrom
idea/response-cache
Open

Add opt-in response caching with --cache-ttl and a cache command#288
jongio wants to merge 1 commit into
mainfrom
idea/response-cache

Conversation

@jongio

@jongio jongio commented Jul 13, 2026

Copy link
Copy Markdown
Owner

What

Adds opt-in on-disk response caching for GET requests, plus a cache command to inspect and clear the store. This closes the gap with restish, which caches responses while az rest and azd rest re-fetch every time.

Flags

  • --cache-ttl <duration>: cache successful GET responses and serve them until the entry is older than the window (30s, 5m, 1h). 0 disables caching. Only 2xx responses are stored, and only for a single request (--repeat 1). A cache hit skips token acquisition.
  • --no-cache: ignore any cached entry, send the request, then refresh the cache with the new response.

Command

  • azd rest cache path: print the cache directory.
  • azd rest cache clear: delete all cached responses.

Behavior

  • Entries are keyed by method, final URL, and resolved scope, so different audiences or query params never collide.
  • Storage lives under the user cache directory with owner-only permissions (0700 dir, 0600 files) since bodies can hold sensitive data.
  • An invalid --cache-ttl exits with code 2 before any request work happens.
  • A corrupt or expired entry is a miss, never an error. A cache write failure prints a note and still serves the response.

Tests

  • Unit: TTL parsing, key stability, round-trip, expiry, corrupt-miss, permissions, clear.
  • Execute-level: second identical GET served from cache, --no-cache refresh, non-2xx not cached, non-GET not cached, invalid TTL exit code 2.
  • cache path / cache clear command output.

Reference docs updated in web/src/pages/reference.astro.

Closes #283

Cache successful GET responses on disk and serve them until the entry is
older than --cache-ttl. A cache hit skips both the network call and token
acquisition, which speeds up repeated reads of the same resource in scripts
and CI.

- --cache-ttl <duration> turns caching on for a single GET (repeat runs still
  measure latency and always hit the network). Only 2xx responses are stored.
- --no-cache bypasses the cached entry and refreshes it with a fresh response.
- azd rest cache path prints the cache directory; azd rest cache clear removes
  all entries.

Entries are keyed by method, final URL, and resolved scope, stored under the
user cache directory with owner-only permissions (0700 dir, 0600 files). An
invalid --cache-ttl exits with code 2 before any request work. A corrupt or
expired entry is treated as a miss, and a cache write failure is a note rather
than a request failure.

Closes #283

Co-authored-by: Copilot App <[email protected]>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 13, 2026
@jongio jongio self-assigned this Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Website Preview

Your PR preview is ready!

📎 Preview URL: https://jongio.github.io/azd-rest/pr/288/

This preview will be automatically cleaned up when the PR is closed.

github-actions Bot added a commit that referenced this pull request Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Test This PR

A preview build (0.5.0-pr288) is ready for testing!

One-Line Install (Recommended)

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.ps1) } -PrNumber 288 -Version 0.5.0-pr288"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 288 0.5.0-pr288

Uninstall

PowerShell (Windows):

iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 288"

Bash (macOS/Linux):

curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 288

Build Info:

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

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add opt-in response caching with --cache-ttl and a cache command

1 participant