FragmentedKeys.KeyRing (fragmented_keys v0.1.1)

Copy Markdown View Source

Factory for creating and managing related keys with predefined configurations.

Define key templates once with define_key/3, then retrieve configured Key objects with get_key_obj/3 or via key_obj/3.

Summary

Functions

Define a reusable key template. Returns updated ring.

Return the current global options map.

Return a Key populated from a defined template.

Return merged options for a tag: global -> per-tag -> extra.

Dynamic key object accessor.

Create a new KeyRing.

Replace the global options applied to all tags.

Set option overrides for a specific tag name.

Create a tag instance with merged options from the ring's configuration.

Types

t()

@type t() :: %FragmentedKeys.KeyRing{
  cache_handlers: term(),
  default_handler_name: term(),
  default_prefix: term(),
  global_options: term(),
  global_tag_options: term(),
  key_definitions: term()
}

Functions

define_key(ring, key, params, globals \\ %{})

Define a reusable key template. Returns updated ring.

params is a list where each element is either a tag name string or a map with at least a "tag" key and optional overrides ("cache_handler", "type", "version", "prefix").

get_global_options(ring)

Return the current global options map.

get_key_obj(ring, key, tag_values)

Return a Key populated from a defined template.

get_tag_options(ring, tag, extra \\ %{})

Return merged options for a tag: global -> per-tag -> extra.

key_obj(ring, key_name, tag_values)

Dynamic key object accessor.

Supports key_obj(ring, :users, ["val1", "val2"]) style access where :users or "users" matches a defined key name (case-insensitive).

new(opts \\ [])

Create a new KeyRing.

Options

  • :cache_handlers — map of name to handler struct (default: %{"memory" => Memory.new()})
  • :default_cache_handler — name of the default handler (default: "memory")
  • :default_prefix — prefix for tag names (default: "DefaultPrefix")
  • :global_options — options merged into every tag (default: %{})
  • :global_tag_options — per-tag-name option overrides (default: %{})

set_global_options(ring, options)

Replace the global options applied to all tags.

set_tag_options(ring, tag, options)

Set option overrides for a specific tag name.

tag(ring, tag_name, instance, options \\ %{})

Create a tag instance with merged options from the ring's configuration.