SuperCache.Stack (SuperCache v1.3.0)

Copy Markdown View Source

Named LIFO stacks backed by SuperCache ETS partitions.

Works transparently in both local and distributed modes — the mode is determined by the :cluster option passed to SuperCache.start!/1.

In distributed mode, structural mutations (push, pop, get_all) are routed to the partition's primary node.

Example

alias SuperCache.Stack

Stack.push("history", :page_a)
Stack.push("history", :page_b)
Stack.pop("history")          # => :page_b
Stack.get_all("history")      # => [:page_a]

Summary

Functions

Return the number of items.

Drain all items top-first. Returns [] for an empty stack.

Pop and return the top value. Returns default (nil) when empty.

Push value onto stack_name. Creates the stack if it does not exist.

Functions

count(stack_name, opts \\ [])

@spec count(
  any(),
  keyword()
) :: non_neg_integer()

Return the number of items.

Options

  • :read_mode:local (default), :primary, or :quorum.

get_all(stack_name)

@spec get_all(any()) :: list()

Drain all items top-first. Returns [] for an empty stack.

pop(stack_name, default \\ nil)

@spec pop(any(), any()) :: any()

Pop and return the top value. Returns default (nil) when empty.

push(stack_name, value)

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

Push value onto stack_name. Creates the stack if it does not exist.