Test Your SuperAPI Cache
Learn how to test and verify your SuperAPI caching system is working correctly
Testing Your SuperAPI Gateway
Once your SuperAPI gateway shows as Healthy and your cache shows as active in the dashboard, it's ready to start caching your API responses. This section will guide you through testing your cache implementation and understanding the cache behavior through response headers.
A healthy gateway with active cache means SuperAPI is successfully intercepting requests and can begin serving cached responses according to your endpoint configurations.
Making API Calls Through SuperAPI
When calling your API through SuperAPI, you need to use the SuperAPI DNS endpoint instead of your origin server. This ensures your requests pass through the SuperAPI cache layer, allowing configured endpoints to benefit from caching before the request potentially reaches your origin server.
Required Headers for API Calls
The essential header for all SuperAPI requests is:
SS4-HOST
- The origin server hostname that SuperAPI should route to
For authentication:
- If you configured JWT token authorization when setting up SuperAPI, you must include that same authorization header in your requests
- If you selected "unauthenticated" during SuperAPI configuration, no authorization header is needed
Example API Call
Here's how to make a test API call through your SuperAPI gateway:
In this example:
https://your-gateway.superapi.cloud
is your SuperAPI DNS endpointapi.your-origin-server.com
is your origin server DNS specified in theSS4-HOST
header
Understanding Cache Response Headers
SuperAPI adds specific headers to API responses that help you monitor cache performance and behavior.
Key Cache Headers
When your gateway is active, you'll see these important headers in API responses:
Cache Status Indicators
ss4-cache
- Shows whether the response was served from cache or origin:
HIT
- Response was served from SuperAPI's cache without contacting your origin serverMISS
- Response required a call to your origin server and was then cached for future requests
ss4-cache-key
- A unique identifier for this specific cached response, useful for debugging and cache management
Testing Cache Behavior
Verifying Cache Hits
To test if your cache is working correctly:
- Make the first request - This should result in a
MISS
as the response gets cached - Make the same request again - This should result in a
HIT
as the response comes from cache - Check the response time - Cached responses should be significantly faster
To measure response time, add the -w
flag to your curl command to display timing metrics:
This will show the total request time in seconds, allowing you to compare cache HIT vs MISS performance.
Example Test Sequence
Testing Cache Invalidation
To verify that your invalidate endpoints properly invalidate cache:
- Make a GET request to cache a response (
ss4-cache: HIT
) - Make a Database Update to a relevant row that would invalidate the cache.
- Repeat the GET request - should now show
ss4-cache: MISS
as cache was invalidated
When you see ss4-cache: MISS
in the response, SuperAPI will also include an additional header ss4-cache-miss-reason
that explains why the cache was missed:
MISSING
- The requested data was not found in the cache (typical for first-time requests)DATA CHANGED
- The cache was invalidated due to a Update/Delete operation or database change
If you have configured invalidation APIs in SuperAPI, you can call these invalidate APIs to invalidate specific cache entries. Additionally, any direct database edits related to your Tables of Interest will also automatically invalidate the cache for affected endpoints.
Example Cache Invalidation Test
Troubleshooting Common Issues
Cache Always Shows MISS
Possible causes:
- TTL set too low
- Parameters not properly mapped
- Request headers varying between calls
Cache Not Invalidating
Possible causes:
- Invalidate endpoint not configured
- Parameter relationships not matching between GET and Invalidate endpoints
- Tables of Interest not properly configured
Authentication Errors
Ensure your Authorization header includes the correct bearer token and that your SuperAPI credentials are valid.
Best Practices for Testing
- Test with consistent parameters - Use the same exact URL and parameters when testing cache behavior
- Monitor cache keys - Different cache keys indicate different cached responses
- Test edge cases - Verify cache behavior with various parameter combinations
- Document your tests - Keep track of which endpoints are configured and their expected cache behavior
By systematically testing your SuperAPI cache implementation, you can ensure optimal performance and verify that your caching strategy works as intended across all configured endpoints.