Caching, Pagination and Filtering in Data API Builder
This lesson explains DAB caching levels, cursor pagination and the filtering, sorting and search options of REST and GraphQL.
Learning outcomes
After completing this lesson, you will be able to:
- Explain entity caching and the L1 and L1L2 levels.
- Describe cursor pagination in REST and GraphQL.
- Distinguish between REST and GraphQL filtering options.
Caching
Caching is enabled globally with runtime.cache.enabled and then per entity. An entity's cache object sets enabled, ttl-seconds (inheriting the global value, 5 seconds by default) and level: L1 is an in-memory cache in each DAB instance, while L1L2 (the default) adds a distributed level 2 cache in Redis, configured under runtime.cache.level-2, which scaled-out instances share. Cached GET and GraphQL query results are returned without querying the database until the TTL expires, so clients may see data up to the TTL old.
dab configure --runtime.cache.enabled true
dab update Product --cache.enabled true --cache.ttl 60DAB caching
Pagination
DAB uses cursor (keyset) pagination. runtime.pagination.default-page-size (100) sets how many rows a request returns when the client does not ask, and max-page-size (100,000) caps any request. In REST, $first=n sets the page size and the response includes a nextLink with an $after cursor for the next page. In GraphQL, first and after arguments page through results, and the response contains items, hasNextPage and endCursor. Cursors are stable as rows are added, unlike offset paging.
Pagination
Filtering, sorting, selecting and searching
The REST and GraphQL query options are compared in the following table.
GET /api/Product?$filter=CategoryID eq 3 and ListPrice lt 200&$orderby=ListPrice desc&$select=ProductID,Name,ListPrice&$first=20Filters are translated into parameterized T-SQL, so they are safe from injection and use indexes on the filtered columns. For richer searching, such as full-text, vector or hybrid search, the logic is written as a stored procedure and exposed as an entity, because the built-in operators only compare values.
A REST query that fails
A catalogue under load
A product catalogue served by three DAB instances in Azure Container Apps receives thousands of identical requests per minute. Prices change only a few times a day, and a delay of up to two minutes is acceptable. Database CPU is high. What should the developer configure?
Enable caching globally and on the Product entity with ttl-seconds of 120 and level L1L2, with a Redis level 2 cache shared by the three instances. Repeated reads are then served from cache, and the TTL matches the acceptable staleness. L1 alone would work per instance but each instance would query the database separately, and increasing max-page-size does not reduce the number of requests.
What is DAB's default page size?
Show answer
100 rows; max-page-size, 100,000 by default, caps any request.
Exam Tips
Remember for the exam
- Reduce repeated reads: entity cache with ttl-seconds; share across instances: L1L2 with Redis.
- Default page size 100; next page via nextLink ($after) or endCursor.
- String matching such as contains and startsWith: GraphQL filter operators.
- Full-text or vector search through DAB: a stored procedure entity.