Caching
Contents
Endpoints is in beta
Endpoints is currently in early beta. While in beta, endpoints is free to use.
We're always looking for feedback to improve endpoints, please reach out to us directly in app.
Caching stores query results temporarily so repeated calls don't re-run the query. This is different from materialization, which pre-computes and stores results on a schedule.
How caching works
When you call an endpoint:
- PostHog checks if there's a cached result that's still fresh
- If yes, it returns the cached result immediately
- If no, it runs the query and caches the result
Cache age
You can set a custom cache duration per endpoint in the Configuration tab. The allowed range is:
- Minimum: 5 minutes (300 seconds)
- Maximum: 24 hours (86,400 seconds)
If not set, PostHog uses default caching behavior.
The refresh parameter
Control caching behavior when calling an endpoint:
| Value | Behavior |
|---|---|
blocking (default) | Returns cached result if fresh, otherwise runs query |
force_blocking | Always runs a fresh query, ignoring cache |
Terminal
Caching vs materialization
| Feature | Caching | Materialization |
|---|---|---|
| Storage | Temporary | Persistent (S3) |
| Refresh | On demand | Scheduled |
| With parameters | Works | Falls back to direct execution |
| Best for | Moderate traffic, real-time needs | High traffic, expensive queries |
Use caching when you need relatively fresh data. Use materialization when query speed matters more than freshness.