Skip to content

Commit

Permalink
Add support for startup matching documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed Oct 14, 2024
1 parent 4ce6cfc commit 71f134b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/cachex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ defmodule Cachex do
#
# Without this, Cachex is not compatible per Elixir's documentation.
@spec start_link(atom | Keyword.t()) :: {atom, pid} | {:error, :invalid_name}
def start_link([name | options]) when is_atom(name) and is_list(options),
do: start_link(name, options)

def start_link(options) when is_list(options) do
case Keyword.fetch(options, :name) do
{:ok, name} ->
Expand Down
2 changes: 2 additions & 0 deletions test/cachex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ defmodule CachexTest do
# create two caches using `Cachex.start_link/1`
{:ok, _pid} = Cachex.start_link(:child_spec1)
{:ok, _pid} = Cachex.start_link(name: :child_spec2)
{:ok, _pid} = Cachex.start_link([:child_spec3])

# verify that both are at least alive in some way
{:ok, _cache1} = Cachex.inspect(:child_spec1, :cache)
{:ok, _cache2} = Cachex.inspect(:child_spec2, :cache)
{:ok, _cache2} = Cachex.inspect(:child_spec3, :cache)
end
end

0 comments on commit 71f134b

Please sign in to comment.