5.2 KiB
Axios Cache Interceptor Flow Diagrams
This directory contains comprehensive Mermaid diagrams that explain the internal flow of the axios-cache-interceptor library. These diagrams help developers understand how requests are processed, cached, and returned.
Diagrams Overview
1. request-response-flow-overview.mermaid
High-level overview showing the complete journey of a request through the interceptor system:
- Client request → Request Interceptor → Adapter → Response Interceptor → Client response
- Shows major decision points and cache states
- Best starting point for understanding the library
2. request-interceptor-detailed.mermaid
Detailed flow of the request interceptor showing:
- Cache key generation
- URL filtering (ignoreUrls, allowUrls)
- Cache takeover header injection
- Cache state checks (empty, stale, cached, loading, must-revalidate)
- Concurrent request handling with deferred promises
- Conditional header addition for stale requests
- All debug messages and their conditions
3. response-interceptor-detailed.mermaid
Detailed flow of the response interceptor for successful responses:
- Cached response detection
- Cache predicate evaluation
- Cache update logic for other entries
- Header interpretation flow
- TTL calculation (from headers or config)
- Cache storage and waiting request resolution
- All debug messages in the success path
4. response-error-interceptor-detailed.mermaid
Detailed flow of the response interceptor error handler:
- Error type validation
- staleIfError logic evaluation
- Stale data return conditions
- Cache cleanup on errors
- Waiting request rejection
- All debug messages in the error path
5. cache-states-transitions.mermaid
State diagram showing all possible cache states and their transitions:
- empty: No cached data
- cached: Fresh data available
- stale: Expired but potentially usable data
- loading: Request in progress
- must-revalidate: Requires server validation
- Explains when and why states change
6. debug-messages-guide.mermaid
Comprehensive guide to all debug messages:
- What each message means
- What action is being taken
- Why the condition occurred
- What the result will be
- Helps troubleshoot issues like #578
7. header-interpreter-flow.mermaid
Detailed flow of HTTP header interpretation:
- Cache-Control directive parsing
- max-age, immutable, no-cache, no-store handling
- Age header processing
- Stale directive handling (max-stale, stale-while-revalidate)
- Expires header fallback
- Priority and return value explanations
How to Use These Diagrams
For Developers
- Start with
request-response-flow-overview.mermaidto understand the big picture - Use
cache-states-transitions.mermaidto understand when cache states change - Dive into specific interceptor diagrams when debugging issues
- Reference
debug-messages-guide.mermaidwhen analyzing debug output
For Debugging
When you see unexpected behavior:
- Enable debug mode in your axios-cache-interceptor config
- Find the debug message in
debug-messages-guide.mermaid - Follow the corresponding flow in the detailed interceptor diagrams
- Understand what conditions led to that path
For Understanding Issues
For issues like #578 (hard to understand debug output):
- The
debug-messages-guide.mermaidprovides context for every message - Each message explains the "what", "why", and "what next"
- Color coding indicates message severity/type
Viewing the Diagrams
Online Viewers
- Mermaid Live Editor - Paste diagram content
- GitHub renders .mermaid files natively in the web interface
- VS Code with Mermaid extension
In Documentation
These diagrams can be embedded in the documentation site at docs/ directory.
Command Line
# Install mermaid CLI
npm install -g @mermaid-js/mermaid-cli
# Generate PNG/SVG from .mermaid files
mmdc -i request-response-flow-overview.mermaid -o request-response-flow-overview.png
Color Legend
In the diagrams, colors indicate different types of nodes:
- Green: Success paths, cached responses, good outcomes
- Yellow: Debug messages, information, warnings
- Orange: Stale data, partial success
- Red: Errors, cache rejections, failures
- Blue: Process steps, data flow, decisions
- Light Blue: Informational notes, explanations
Related Issues and PRs
- Issue #578: Understanding debug output - Addressed by
debug-messages-guide.mermaid - Issue #579: cacheTakeover and Pragma header explanation
- Issue #471: iOS Safari compatibility requiring Pragma header
Contributing
If you find errors in these diagrams or want to improve them:
- Edit the .mermaid files
- Test them in Mermaid Live Editor
- Submit a pull request with your improvements
Notes on Cache Takeover
The cacheTakeover option (detailed in request-interceptor-detailed.mermaid) sets these headers:
Cache-Control: no-cache, no-store, must-revalidate, max-age=0Pragma: no-cacheExpires: 0
The Pragma header is specifically needed for iOS Safari due to a WebKit bug (#170714). Even though it's an HTTP/1.0 header, it's still required for proper cache prevention on iOS devices. This is documented in issues #579 and #471.