EDA.Cache.Policy behaviour (EDA v0.3.0)

Copy Markdown View Source

Cache admission policy behaviour and dispatcher.

Controls whether incoming Discord data should be cached or skipped. Used by cache modules to gate writes on the hot path.

Policy values

  • :all (default) — cache everything
  • :none — cache nothing
  • module — a module implementing the EDA.Cache.Policy behaviour
  • fn/3 — an anonymous function fn entity, key, value -> :cache | :skip end

Example

config :eda,
  cache: [
    presences: [policy: :none],
    channels: [policy: fn _entity, _key, ch ->
      if ch["type"] in [0, 2, 5], do: :cache, else: :skip
    end]
  ]

Summary

Callbacks

Decides whether the given entity should be cached.

Functions

Dispatches a policy check.

Types

decision()

@type decision() :: :cache | :skip

entity()

@type entity() ::
  :guild | :user | :channel | :member | :role | :voice_state | :presence

Callbacks

should_cache?(entity, key, value)

@callback should_cache?(entity(), key :: term(), value :: map()) :: decision()

Decides whether the given entity should be cached.

Functions

check(fun, entity, key, value)

@spec check(term(), entity(), term(), map()) :: decision()

Dispatches a policy check.

Returns :cache or :skip depending on the configured policy.