Skip to content

Conversation

@mcollina
Copy link
Member

Summary

  • Add an origins option to the cache interceptor that filters which origins can be cached
  • Support string matching (case insensitive) and RegExp patterns
  • Default behavior (undefined) preserves current behavior - cache all origins
  • Empty array caches nothing

Usage

interceptors.cache({
  origins: ['localhost', /^api\.example\.com$/]
})

Test plan

  • String matching - cache when origin matches
  • String matching - skip cache when origin doesn't match
  • RegExp matching - cache when origin matches
  • RegExp matching - skip cache when origin doesn't match
  • Mixed array - cache when any entry matches
  • Default behavior - cache all when undefined (backward compatible)
  • Empty array - cache nothing
  • Validation - throw on invalid types
  • Case insensitivity for string matching
  • Different hosts are treated as different origins
  • TypeScript type tests with tsd

Add an `origins` option to the cache interceptor that allows filtering
which origins can be cached. Only requests to whitelisted origins will
be cached.

- Support string matching (case insensitive)
- Support RegExp patterns
- Default behavior (undefined) caches all origins
- Empty array caches nothing
- Add validation for invalid types
- Include TypeScript type definitions and tsd tests

Signed-off-by: Matteo Collina <[email protected]>
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.89%. Comparing base (250efc8) to head (0fa02b6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4739      +/-   ##
==========================================
- Coverage   92.89%   92.89%   -0.01%     
==========================================
  Files         109      109              
  Lines       33886    33928      +42     
==========================================
+ Hits        31478    31517      +39     
- Misses       2408     2411       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina requested review from Uzlopak and ronag January 16, 2026 15:06
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.

3 participants