JevDSL.Cache.ETS (jev_dsl v0.1.0)

Copy Markdown View Source

Built-in zero-dependency ETS cache adapter implementing JevDSL.Cache.

Provides concurrent read/write access with monotonic TTL expiration so JevDSL works out of the box in any Elixir application without external cache dependencies.

Supervision & ETS Table Ownership

JevDSL.Cache.ETS can be used in two modes:

  1. Supervised Mode (Recommended for Production & async: true Tests): Add {JevDSL.Cache.ETS, name: MyApp.JevCache, table: :my_app_jev_cache} to your application's supervision tree (or start_supervised!/1 in tests). The GenServer owns the ETS table and periodically prunes expired keys.

  2. Zero-Config On-Demand Mode: If get/2 or put/3 is called before a server is started, ensure_table/1 creates the named ETS table and attaches a lightweight heir receiver so the table survives even if the first caller was a short-lived Task or request process.

Summary

Functions

Returns a child specification with :id scoped to :name or :table so multiple JevDSL.Cache.ETS instances can be supervised in the same tree or test.

Clears all cached entries in the ETS cache table.

Deletes all expired entries from table and returns the number of evicted keys.

Starts an ETS cache owner process linked to the caller's supervision tree.

Functions

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child specification with :id scoped to :name or :table so multiple JevDSL.Cache.ETS instances can be supervised in the same tree or test.

clear(table \\ :jev_dsl_ets_cache)

@spec clear(atom()) :: :ok

Clears all cached entries in the ETS cache table.

prune_expired(table \\ :jev_dsl_ets_cache)

@spec prune_expired(atom()) :: non_neg_integer()

Deletes all expired entries from table and returns the number of evicted keys.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts an ETS cache owner process linked to the caller's supervision tree.

Options

  • :name - Process registration name for the ETS owner server. The default value is JevDSL.Cache.ETS.

  • :table (atom/0) - Named ETS table atom. The default value is :jev_dsl_ets_cache.

  • :cleanup_interval - Interval in milliseconds between automatic expired-entry sweeps. The default value is 300000.