-
-
Notifications
You must be signed in to change notification settings - Fork 3
Response Caching
github-actions edited this page May 15, 2026
·
5 revisions
UNCORS provides response caching to optimize development workflows by reducing latency for expensive or frequently repeated requests. Cache entries are matched using URL glob patterns.
Benefits:
- Faster response times for repeated requests
- Reduced load on upstream servers during development
- Improved performance when working with slow APIs
- Useful for caching heavy computations or large datasets
Configuration:
Specify URL patterns to cache for each mapping:
mappings:
- from: ...
to: ...
cache:
- /api/info
- /api/users/**Cache patterns use glob syntax to match URL paths. The following special characters are supported:
| Special Term | Meaning |
|---|---|
* |
Matches any sequence of non-path-separators |
/**/ |
Matches zero or more directories |
? |
Matches any single non-path-separator character |
[class] |
Matches any single non-path-separator character against a class of characters (see Character Classes) |
{alt1,...} |
Matches a sequence of characters if one of the comma-separated alternatives matches |
Important notes:
- Escape special characters with backslash:
\*,\?,\[ - Double star
**must be surrounded by path separators:/**/ - Incorrect:
path/to/**.txt(acts likepath/to/*.txt) - Correct:
path/to/**/*.txt(matches files in subdirectories)
Character classes match single characters against a set or range:
| Class | Meaning |
|---|---|
[abc] |
Matches any single character within the set |
[a-z] |
Matches any single character in the range |
[^class] |
Matches any single character which does not match the class |
[!class] |
Same as ^: negates the class |
Configure caching behavior globally using the cache-config section:
cache-config:
methods: [GET]
expiration-time: 10m
max-size: 104857600| Property | Type | Default | Description |
|---|---|---|---|
methods |
array | [GET] |
HTTP methods to cache (e.g., GET, POST, PUT) |
expiration-time |
duration | 30m |
Time until a cached response is evicted |
max-size |
integer | 104857600 |
Maximum total cache size in bytes (default 100 MB) |
Duration format: <number><unit> where unit is s (seconds), m
(minutes), or h (hours)
Examples:
-
30s- 30 seconds -
5m- 5 minutes -
2h- 2 hours -
1h 30m- 1 hour 30 minutes
- Hit - Response is returned immediately from cache
- Miss - Request is forwarded to the upstream server; response is stored in cache
-
Evicted (after
expiration-timeor whenmax-sizeis reached) - Cache entry is removed; next request fetches fresh data from upstream
mappings:
- from: http://localhost
to: https://api.example.com
cache:
- /api/users
- /api/posts/*
- /api/data/**/*.json
cache-config:
methods: [GET]
expiration-time: 5m
max-size: 52428800cache-config:
methods: [GET, POST, PUT]
expiration-time: 2m
max-size: 104857600
mappings:
- from: http://localhost
to: https://api.example.com
cache:
- /api/search
- /api/query/**