View Source JSV.Resolver.Cache (jsv v0.2.0)

An in-memory cache to store resources resolved by the JSV.Resolver.BuiltIn resolver implementation.

The cache implementation is very basic an serves as a dependency-free solution for applications building schemas at runtime.

If all your schemas are built at compile-time, you do not need this cache because it is not started during compilation, for simplicity sake.

A cache instance is automatically started with the :jsv OTP application with Cache as a name. You can use the cache by passing that name as the first arguments of the functions, for instance:

Cache.get_or_generate(Cache, :some_key, fn -> {:ok, "value"} end)

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a cache identified with a name.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_or_generate(name, key, fun)

@spec get_or_generate(GenServer.name(), term(), (-> {:ok, term()} | {:error, term()})) ::
  {:ok, term()} | {:error, term()}

start_link(opts)

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Starts a cache identified with a name.

Options

  • :name (atom/0) - Required. The name for the cache and the public ETS table.

This function also supports other GenServer options.