Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
880 stars 179 forks source link

⭐ [Enhancement]: "Complete" Cache Features #2253

Open JerryNixon opened 3 months ago

JerryNixon commented 3 months ago

What is it?

Today, in-memory caching is enabled globally and at the entity level.

{
  "runtime": {
    "caching": {
      "enabled": true,
      "ttl-seconds": 10
    }
  }
}

And then at the entity level:

{
  "entities": {
    "Book": {
      "caching": {
        "enabled": true,
        "ttl-seconds": 10
      }
    }
  }
}

Proposal 0: Support Stored Procedures

There’s no technical reason to omit procs.

image

In a recent Dab community poll, 25% of exposed objects were stored procs.

Proposal 1: CLI Enhancement

  1. Add caching to the add and update verbs.
  2. When enabled for an entity, auto-enable globally.

This is not a breaking change, as caching was not previously in the CLI.

Proposal 2: HTTP Headers

Add support for Request Headers:

  1. Cache-Control: no-cache: Forces a query submission to the database.
  2. Cache-Control: no-store: Prevents caching the response.
  3. Cache-Control: only-if-cached: Returns 504 Gateway Timeout if unavailable.

⚠️ These request headers are always echoed back in the response headers.

Add support for Response Headers:

  1. When caching is involved, always add Cache-Control: public/private, max-age: {ttl-seconds}.

This would introduce the following configuration:

{
  "entities": {
    "Book": {
      "caching": {
        "enabled": true,
        "ttl-seconds": 10,
        "response-directive": "public|private (default: public)" // new
      }
    }
  }
}

Proposal 3: Always return no-cache when not caching.

  1. When caching is not applied, always add Cache-Control: no-cache.

Related Issues to Close

seantleonard commented 3 months ago

fyi for cache http headers https://github.com/Azure/data-api-builder/blob/main/docs/design/query-caching.md#disclaimer-about-applicability-to-this-design-doc