Skip to content

Opinionated defaults

paceapi is opinionated. Where a choice has to be made it picks the safe behavior, and it raises configuration mistakes when a limit, cache route, or middleware is declared instead of on the first request. This page lists the defaults and how to change each.

Rate limiting

  • Limits count by client address: key= defaults to client_ip. key=None is rejected (Keys).
  • A key that returns nothing fails the request: on_missing_key="raise" raises MissingKeyError, so a broken key cannot switch a limit off unnoticed. Pass "skip" to exempt such requests.
  • Each route has its own bucket: Pass scope= to share one bucket across routes (Multiple limits).
  • Sliding window: The default algorithm. FixedWindow and TokenBucket are opt-in (Algorithms).
  • Store failures fail open: on_store_error="allow" lets requests through, logs the failure, and sends no rate limit headers. Pass "deny" or "raise" to change it (Failure modes).
  • X-RateLimit-* headers are sent: Pass header_style=None to omit them (Headers and errors).

Caching

  • Signed-in requests are cached only when the cache knows the caller: A request with Authorization or Cookie is not cached on an @ns.response route. Cache(credentials=["Authorization", "Cookie"]) names the headers callers sign in with and turns on a cached copy per caller. An app that uses Starlette's AuthenticationMiddleware with a user class that defines identity gets per-caller copies without credentials=. shared=True caches one copy for every caller (Caching responses).
  • Cache-Control: public is not sent to a signed-in caller: An endpoint that sets it on a response it returns has it removed for such requests. An HTTPException it raises, and a method outside methods=, are sent as they are.
  • entity= on a decorator is for invalidation only: It names what a value is about and does not decide who may be sent it. (ResponseCacheMiddleware(entity=) is different: there it is the key that says whose a response is.)
  • Values are stored as JSON: JSONSerializer is the default; PickleSerializer is opt-in (Quickstart).
  • Failed reads are misses; failed writes and invalidations raise: A silently lost invalidation would leave stale data behind (Consistency guarantees).

Traffic management

  • No queueing: ConcurrencyLimit(wait=0) rejects with 503 as soon as every slot is held. Pass wait= for bounded queueing (Concurrency limits).
  • Unlisted priorities are never shed: LoadShedder only sheds the classes it is given (Load shedding).
  • Deadlines need async endpoints: @deadline.enforced() rejects sync endpoints, because a worker thread cannot be cancelled (Deadlines).
  • Signed-in callers coalesce only with themselves: CoalescingMiddleware matches on Authorization and Cookie by default (Request coalescing).

Everywhere

  • Mistakes fail at startup: Options are validated when they are declared. A wrong type, an unknown policy, or a key that cannot work raises before the app serves a request.
  • No global state: Every Limiter, Cache, and limit is an object you create and pass.
  • asyncio only: Timeouts, locks, and tasks use asyncio; Trio is not supported.