← tests

cache

The framework's response cache: the handler skipped and a stored answer replayed, keyed by a path segment and by request header, and kept for 30 seconds.

Comparable across stores rather than across frameworks. Several frameworks ship no response cache and run a package chosen for them, so a ranking that carried these rows would be ranking the package.

testheftrequestbasewhat differs from the base
cache.large3GET /cache/large/{draw.key}json.largethe handler skipped and a stored response replayed
cache.medium1GET /cache/medium/{draw.key}json.mediumthe handler skipped and a stored response replayed
cache.small1GET /cache/small/{draw.key}json.smallthe handler skipped and a stored response replayed
cache.vary_one1GET /cache/vary/one/{draw.key}cache.smallthe stored response keyed by request headers as well as by path
cache.vary_many1GET /cache/vary/many/{draw.key}cache.vary_onethe stored response keyed by request headers as well as by path

cache.large

heft 3

base json.large

The handler skipped and a stored answer written back, under one of four keys the path names. Read against json.large, the difference is the store answering instead of the framework, which is why this row asserts the serial repeated rather than changed.

Request

GET /cache/large/{draw.key}

No body.

Expected response

HTTP 200
x-rb-serialrepeats, so a stored answer was replayed

payload items.large

{"size":"large","count":1425,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true},{"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true},{"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true},{"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true},{"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true},{"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true},{"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false},{"id":8,"name":"oak-lamp-8662","category":"kit
… 128,510 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/cache/large.ts
tests/cache/large.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/cache/large/{draw.key}";

export default performanceTest({
  id: { family: "cache", name: "large" },
  path,
  base: "json.large",
  varies: "response_cache",
  heft: 3,
  about:
    "The handler skipped and a stored answer written back, under one of four " +
    "keys the path names. Read against json.large, the difference is the store " +
    "answering instead of the framework, which is why this row asserts the " +
    "serial repeated rather than changed.",

  request: (c) => c.get(`/cache/large/${c.draw.key()}`).okWith(items.large).replayed(),
});

cache.medium

heft 1

base json.medium

The handler skipped and a stored answer written back, under one of four keys the path names. Read against json.medium, the difference is the store answering instead of the framework, which is why this row asserts the serial repeated rather than changed.

Request

GET /cache/medium/{draw.key}

No body.

Expected response

HTTP 200
x-rb-serialrepeats, so a stored answer was replayed

payload items.medium

{"size":"medium","count":89,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true},{"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true},{"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true},{"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true},{"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true},{"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true},{"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false},{"id":8,"name":"oak-lamp-8662","category":"kitc
… 7,953 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/cache/medium.ts
tests/cache/medium.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/cache/medium/{draw.key}";

export default performanceTest({
  id: { family: "cache", name: "medium" },
  path,
  base: "json.medium",
  varies: "response_cache",
  heft: 1,
  about:
    "The handler skipped and a stored answer written back, under one of four " +
    "keys the path names. Read against json.medium, the difference is the store " +
    "answering instead of the framework, which is why this row asserts the " +
    "serial repeated rather than changed.",

  request: (c) => c.get(`/cache/medium/${c.draw.key()}`).okWith(items.medium).replayed(),
});

cache.small

heft 1

base json.smallbase of cache.vary_one

The handler skipped and a stored answer written back, under one of four keys the path names. Read against json.small, the difference is the store answering instead of the framework, which is why this row asserts the serial repeated rather than changed.

Request

GET /cache/small/{draw.key}

No body.

Expected response

HTTP 200
x-rb-serialrepeats, so a stored answer was replayed

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}]}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/cache/small.ts
tests/cache/small.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/cache/small/{draw.key}";

export default performanceTest({
  id: { family: "cache", name: "small" },
  path,
  base: "json.small",
  varies: "response_cache",
  heft: 1,
  about:
    "The handler skipped and a stored answer written back, under one of four " +
    "keys the path names. Read against json.small, the difference is the store " +
    "answering instead of the framework, which is why this row asserts the " +
    "serial repeated rather than changed.",

  request: (c) => c.get(`/cache/small/${c.draw.key()}`).okWith(items.small).replayed(),
});

cache.vary_one

heft 1

base cache.smallbase of cache.vary_many

The stored answer keyed by a request header as well as by the path. One header with two values, picked per instance, so a store that ignores the vary header holds four entries where the plan sent eight keys.

Request

GET /cache/vary/one/{draw.key}
x-rb-tenantalpha or beta picked per request

No body.

Expected response

HTTP 200
x-rb-serialrepeats, so a stored answer was replayed

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}]}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/cache/vary-one.ts
tests/cache/vary-one.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/cache/vary/one/{draw.key}";
/** Two tenants, so a store that ignores the header holds one entry where two keys were sent. */
const tenants = ["alpha", "beta"];

export default performanceTest({
  id: { family: "cache", name: "vary_one" },
  path,
  base: "cache.small",
  varies: "cache_key",
  heft: 1,
  about:
    "The stored answer keyed by a request header as well as by the path. One " +
    "header with two values, picked per instance, so a store that ignores the " +
    "vary header holds four entries where the plan sent eight keys.",

  request: (c) =>
    c
      .get(`/cache/vary/one/${c.draw.key()}`)
      .header("x-rb-tenant", c.draw.choice(tenants))
      .okWith(items.small)
      .replayed(),
});

cache.vary_many

heft 1

base cache.vary_one

The same thing keyed on three headers instead of one. Read against cache.vary_one, the difference is thirty-two distinct keys where there were eight, which is what a store has to be sized against rather than what it costs to read.

Request

GET /cache/vary/many/{draw.key}
x-rb-channelweb or app picked per request
x-rb-regioneu or us picked per request
x-rb-tenantalpha or beta picked per request

No body.

Expected response

HTTP 200
x-rb-serialrepeats, so a stored answer was replayed

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}]}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/cache/vary-many.ts
tests/cache/vary-many.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/cache/vary/many/{draw.key}";
/** Two values of each header, so a store that ignores one holds half the entries it was sent. */
const channels = ["web", "app"];
const regions = ["eu", "us"];
const tenants = ["alpha", "beta"];

export default performanceTest({
  id: { family: "cache", name: "vary_many" },
  path,
  base: "cache.vary_one",
  varies: "cache_key",
  heft: 1,
  about:
    "The same thing keyed on three headers instead of one. Read against " +
    "cache.vary_one, the difference is thirty-two distinct keys where there were " +
    "eight, which is what a store has to be sized against rather than what it " +
    "costs to read.",

  request: (c) =>
    c
      .get(`/cache/vary/many/${c.draw.key()}`)
      .header("x-rb-channel", c.draw.choice(channels))
      .header("x-rb-region", c.draw.choice(regions))
      .header("x-rb-tenant", c.draw.choice(tenants))
      .okWith(items.small)
      .replayed(),
});