MailAuth.Resolver.Cached (MailAuth v0.1.0)

Copy Markdown View Source

A resolver that wraps another one with an ETS cache.

Answers are kept for their TTL, capped at one hour. "No such name" and "no such record" answers are kept too, as RFC 2308 says. Temporary failures are not kept.

Start it in your supervision tree:

children = [
  {MailAuth.Resolver.Cached, resolver: MailAuth.Resolver.Inet, max_size: 10_000}
]

and use it:

MailAuth.authenticate(raw, resolver: MailAuth.Resolver.Cached)

Options for start_link/1:

  • :name: the cache's name. Default MailAuth.Resolver.Cached. With another name, pass cache: name to every call
  • :resolver: the resolver to ask on a miss. Default MailAuth.Resolver.Inet
  • :max_size: the most answers to keep. Default 10 000
  • :max_ttl: the longest time to keep an answer, in seconds. Default 3600

When the cache is full, expired answers are removed first; if it is still full, the oldest answers go.

Summary

Functions

Removes every answer from the cache.

Starts the cache.

Functions

clear(name \\ __MODULE__)

@spec clear(atom()) :: :ok

Removes every answer from the cache.

start_link(opts \\ [])

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

Starts the cache.