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 caching 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,
    "level": "L1"
  }
}
  • enabled: Required. Enables caching for this specific entity.
  • ttl-seconds: Optional. If not specified, inherits from the global time-to-live (TTL) value.
  • level: Optional. Controls which cache tiers are used. L1 uses in-memory cache only; L1L2 (default) uses both in-memory and distributed cache.

See entity cache settings.

Note

The Data API builder 2.0 functionality described in this section is currently in preview and might change before general availability. For more information, see What's new in version 2.0.

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.