GenServer owner for ETS tables managed by SuperCache.
This process owns the lifecycle of all ETS tables used for caching. Tables are created, tracked, and deleted through this GenServer so that:
- Tables are automatically deleted when the owning process terminates.
- The table list is tracked in state for clean shutdown.
- Creation respects the global
:key_posand:table_typeconfiguration.
Lifecycle
start_link/1starts the GenServer under a given name.new_table/2creates a new ETS table with the configured options.delete_table/2removes a specific table.- On shutdown,
terminate/2deletes all tracked tables to free memory.
Configuration
Tables are created with the following options:
:keypos— derived fromConfig.get_config(:key_pos) + 1(ETS is 1-based):table_type— fromConfig.get_config(:table_type)(:set,:bag, etc.):public— accessible by any process:named_table— addressable by atom name{:write_concurrency, true}— optimised for concurrent writes{:read_concurrency, true}— optimised for concurrent reads{:decentralized_counters, true}— reduces contention on counter updates
Example
{:ok, pid} = SuperCache.EtsHolder.start_link(:my_ets_owner)
SuperCache.EtsHolder.new_table(:my_ets_owner, :my_cache_table)
:ets.insert(:my_cache_table, {:key, "value"})
SuperCache.EtsHolder.stop(:my_ets_owner)
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all records from a specific ETS table without deleting it.
Clears all records from all tracked ETS tables.
Deletes a specific ETS table tracked by this GenServer.
Creates a new named ETS table owned by this GenServer.
Starts the EtsHolder GenServer under the given name.
Stops the EtsHolder GenServer and deletes all owned ETS tables.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Clears all records from a specific ETS table without deleting it.
Returns true on success.
@spec clean_all(atom()) :: :ok
Clears all records from all tracked ETS tables.
Tables are not deleted — only their contents are removed.
Deletes a specific ETS table tracked by this GenServer.
The table is removed from ETS and from the internal tracking list. No-op if the table is not found.
Creates a new named ETS table owned by this GenServer.
The table is configured according to the current :key_pos and
:table_type settings in SuperCache.Config.
Examples
SuperCache.EtsHolder.new_table(:my_owner, :users_cache)
# => :ok
Starts the EtsHolder GenServer under the given name.
The process enters hibernation when idle to reduce memory footprint.
Stops the EtsHolder GenServer and deletes all owned ETS tables.
The terminate/2 callback ensures all tracked tables are removed
before the process exits.