Performance5 min read•Audience: Developers
HTML Output & Caching Headers
Understand the HTML output caching strategy: SHA-256 content hashing, Redis storage, and X-Cache headers.
Key Takeaways
- Compiled MJML documents are hashed using SHA-256.
- Compiled HTML is cached in Redis for 24 hours, returning sub-50ms responses for repeated calls.
- Responses include the X-Cache: HIT or X-Cache: MISS header.
Redis Compilation Cache Architecture#
Compiling MJML to HTML requires CPU cycles. To ensure maximum throughput at scale:
- When a template is requested, PostBrix calculates a SHA-256 hash of the generated MJML.
- If the hash exists in Redis (
KEYS.mjmlCompiled(contentHash)), the compiled HTML is retrieved instantly (X-Cache: HIT). - Only the dynamic Handlebars variable substitution step runs at request time, achieving throughput exceeding 200 requests/second per container.
Automatic Cache Invalidation#
Whenever a template is saved or published in the PostBrix visual editor:
- A new content hash is generated.
- The next API call triggers a fresh compilation (
X-Cache: MISS), which is immediately stored in Redis for subsequent requests. - No manual cache-clearing commands or API calls are necessary.
Frequently Asked Questions
How do I know if an API response was served from cache?
Inspect the X-Cache response header. It will return "HIT" for cached results and "MISS" for newly compiled templates.
Can I force-bypass the Redis cache for testing?
Pass the query parameter ?bypassCache=true or the header Cache-Control: no-cache in your API request.