PermitEx.Cache (permit_ex v0.3.0)

Copy Markdown View Source

Optional ETS cache for scope data (roles + permissions).

Disabled by default. Enable with:

config :permit_ex,
  cache: true,
  cache_ttl: :timer.minutes(5)

Mutation APIs invalidate cache automatically. Call invalidate/2 or invalidate_all/0 after external changes (raw SQL, another node, etc.).

Summary

Functions

Returns true when caching is enabled via config.

Fetches cached scope data for a user/context pair.

Invalidates cached scope data.

Drops the entire scope cache.

Stores scope data for a user/context pair when caching is enabled.

Functions

enabled?()

Returns true when caching is enabled via config.

get(user_id, context_id)

Fetches cached scope data for a user/context pair.

Returns {:ok, {roles, permissions}} or :miss.

invalidate(user_id, context_id \\ nil)

Invalidates cached scope data.

  • invalidate(user_id, context_id) — one scope (use nil for global)
  • invalidate(user_id, :all) — every context for that user

invalidate_all()

Drops the entire scope cache.

put(user_id, context_id, data)

Stores scope data for a user/context pair when caching is enabled.