Caching

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:

  1. PostHog checks if there's a cached result that's still fresh
  2. If yes, it returns the cached result immediately
  3. 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:

ValueBehavior
blocking (default)Returns cached result if fresh, otherwise runs query
force_blockingAlways runs a fresh query, ignoring cache
Terminal
curl -X POST \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"refresh": "force_blocking"}' \
"<ph_app_host>/api/projects/{project_id}/endpoints/{endpoint_name}/run"

Caching vs materialization

FeatureCachingMaterialization
StorageTemporaryPersistent (S3)
RefreshOn demandScheduled
With parametersWorksFalls back to direct execution
Best forModerate traffic, real-time needsHigh traffic, expensive queries

Use caching when you need relatively fresh data. Use materialization when query speed matters more than freshness.

Community questions

Was this page useful?

Questions about this page? or post a community question.