Edit

Share via


Implement level 1 cache

Level 1 cache in Data API builder reduces redundant requests to the database by temporarily caching entity results in memory. This improves performance for frequent queries and avoids hitting the database unnecessarily.

Enable cache globally

To enable caching, set the global runtime configuration:

"runtime": {
  "cache": {
    "enabled": true,
    "ttl-seconds": 60
  }
}
  • enabled: Required. Turns on caching globally.
  • ttl-seconds: Optional. Defines the default time-to-live (in seconds) for cached items.

See runtime cache settings.

Enable cache per entity

Each entity must also opt in to use cache:

"MyEntity": {
  "cache": {
    "enabled": true,
    "ttl-seconds": 30
  }
}
  • enabled: Required. Enables caching for this specific entity.
  • ttl-seconds: Optional. If not specified, inherits from the global TTL.

See entity cache settings.

Behavior

  • Applies only to REST endpoints.
  • Works on a per-route, per-parameter basis.
  • Cache is invalidated when data is modified (create, update, delete).
  • Entity ttl-seconds overrides global ttl-seconds.

Notes

  • Level 1 cache is in-memory only.
  • Best suited for read-heavy scenarios with low data volatility.