mochi/dataloader_cache

Types

pub opaque type SharedCache

Values

pub fn clear(cache: SharedCache) -> Nil

Wipe all entries from the cache.

pub fn get(
  cache: SharedCache,
  key: key,
) -> option.Option(Result(value, String))

Look up a key. Returns Some(result) if present, None if not cached.

pub fn invalidate(cache: SharedCache, key: key) -> Nil

Remove a key — call this after a mutation that invalidates cached data.

pub fn new(name: String) -> SharedCache

Create an ETS-backed shared cache. The same name always returns the same underlying ETS table, so it is safe to call from multiple processes or on every request — only one table is created per name.

pub fn put(
  cache: SharedCache,
  key: key,
  value: Result(value, String),
) -> Nil

Store a single result.

pub fn put_many(
  cache: SharedCache,
  pairs: List(#(key, Result(value, String))),
) -> Nil

Store multiple results at once.

Search Document