SuperCache.Cluster.DistributedStore (SuperCache v1.5.0)

Copy Markdown View Source

Shared routing helpers used by distributed high-level stores.

Partition resolution

Two consistent schemes are provided — pick one per access pattern:

  • Concrete-key helpers (route_put/2, route_delete/2, local_get/2, local_insert_new/2, local_take/2) resolve the partition from the record or record key itself, so writes, reads and deletes for the same key always land on the same table. The second argument is accepted for API compatibility and ignored.
  • Pattern helpers (local_match/2, route_delete_match/2) cannot hash a match pattern (wildcards change the term), so they scope to a namespace: the partition is derived from the namespace argument and all records for one store must therefore embed that namespace in their key.

Read routing

Reads always go to the local ETS table (eventual consistency by default). Pass read_mode: :primary at the API layer where strong consistency is required.

Summary

Functions

Read ets_key from its partition.

insert_new on the record's partition.

Match-object scan on the namespace's partition.

take on the record's partition.

Route a delete of ets_key, partitioned by the key itself.

Route a pattern delete scoped to the partition derived from namespace.

Route a put of the record {ets_key, value} to the partition derived from ets_key.

Functions

local_get(ets_key, namespace)

@spec local_get(any(), any()) :: [tuple()]

Read ets_key from its partition.

local_insert_new(record, namespace)

@spec local_insert_new(tuple(), any()) :: boolean()

insert_new on the record's partition.

local_match(namespace, pattern)

@spec local_match(any(), tuple()) :: [tuple()]

Match-object scan on the namespace's partition.

local_take(ets_key, namespace)

@spec local_take(any(), any()) :: [tuple()]

take on the record's partition.

route_delete(ets_key, namespace)

@spec route_delete(any(), any()) :: :ok

Route a delete of ets_key, partitioned by the key itself.

route_delete_match(namespace, pattern)

@spec route_delete_match(any(), tuple()) :: :ok

Route a pattern delete scoped to the partition derived from namespace.

route_put(ets_key, value)

@spec route_put(any(), any()) :: true

Route a put of the record {ets_key, value} to the partition derived from ets_key.