# `AbsintheAPQ.Cache.ETS`
[🔗](https://github.com/koode/absinthe_apq/blob/v0.1.0/lib/absinthe_apq/cache/ets.ex#L1)

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.

# `size`

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

Returns the number of queries in the store.

# `start_link`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
