AbsintheAPQ.Cache.ETS (absinthe_apq v0.1.0)

Copy Markdown View Source

A bounded, in-memory AbsintheAPQ.Cache in an ETS table.

Start it in your application's supervision tree:

children = [
  {AbsintheAPQ.Cache.ETS, max_entries: 1_000},
  MyAppWeb.Endpoint
]

It is the default :cache of AbsintheAPQ.DocumentProvider. A store with another :name must be passed explicitly:

children = [{AbsintheAPQ.Cache.ETS, name: MyApp.APQCache}]

document_providers: [
  {AbsintheAPQ.DocumentProvider, cache: {AbsintheAPQ.Cache.ETS, name: MyApp.APQCache}},
  Absinthe.Plug.DocumentProvider.Default
]

Options

  • :name: the name of the process and of its ETS table. Defaults to AbsintheAPQ.Cache.ETS.
  • :max_entries: the most queries the table holds. Defaults to 1_000.

Bounds and eviction

The table never holds more than :max_entries queries. When a new query would go over the limit, the query that was stored first is removed (first in, first out). Reading a query does not change its place, and storing a hash that is already in the table changes nothing. An evicted query costs its clients one extra round trip: the hash-only request misses and the client sends the full query again.

Together with the :max_query_bytes option of AbsintheAPQ.DocumentProvider, this bounds the memory a client can fill: about max_entries * max_query_bytes bytes, or 32 MiB with the defaults.

The table lives in this node's memory only. Every node of a cluster has its own, and a restart empties it; clients then register their queries again.

Concurrency

Reads go straight to the ETS table, from the request process, with read concurrency on. Writes go through this process, one at a time, so the count and the eviction order stay exact.

Summary

Functions

Returns the number of queries in the store.

Starts the store. See the module documentation for the options.

Functions

size(opts \\ [])

@spec size(keyword()) :: non_neg_integer()

Returns the number of queries in the store.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the store. See the module documentation for the options.