Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting Cachex via Supervisor.start_link #383

Closed
lucavenir opened this issue Oct 12, 2024 · 4 comments · Fixed by #384
Closed

Starting Cachex via Supervisor.start_link #383

lucavenir opened this issue Oct 12, 2024 · 4 comments · Fixed by #384

Comments

@lucavenir
Copy link

Hello there,

I really hope I'm not wasting anyone's time here, but I simply went and read the "welcome page/guide" of this (awesome!) package and I've got myself a papercut.

I read from the docs, in regards of starting Cachex in a supervision tree:

children = [
  {Cachex, [:my_cache]},     # with default options
  {Cachex, [:my_cache, []]}  # with custom options
]

So I try this in my phoenix application; I copy-paste the first line in my list of children:

children = [
  ...,
  {Cachex, [:my_cache]},
]

But, Supervisor.start_link gives this error:

** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: Cachex
    ** (EXIT) :invalid_name

Whereas, if I write my cache name like below, no error is raised on startup:

{Cachex, name: :my_cache},

Which makes sense, AFAIK supervisor wants a keyword list as a second argument of the tuple.

But... am I doing this right? Am I missing something?

@lucavenir
Copy link
Author

lucavenir commented Oct 12, 2024

By the way I've read #380 before opening this issue. I've updated my cachex dependency to match exactly 4.0.1, but the behavior is identical.

@whitfin
Copy link
Owner

whitfin commented Oct 12, 2024

Hi @lucavenir!

At a glance, yes, the docs for this are wrong and need to be updated. I can double check when I get a moment, just in case!

@whitfin
Copy link
Owner

whitfin commented Oct 14, 2024

@lucavenir instead of changing the docs, I decided to just make sure that the form shown in the README also works - I did that in #384. I also added checks to make sure this is tested going forward!

It should be released in v4.0.2 if you want to double check that it's all good for you now!

@lucavenir
Copy link
Author

Oh, okay! I'll try this out ASAP.

If anyone's having this same problem, I am currently starting two different Cachex instances like so:

[
  Supervisor.child_spec(
    {Cachex, name: MyApp.Whatever.Module.One},
    id: MyApp.Whatever.Module.One
  ),
  Supervisor.child_spec(
    {Cachex, name: MyApp.Whatever.Module.Two},
    id: MyApp.Whatever.Module.Two
  )
]

I did this when trying to make it work: Supervisor.start_link/2 gives a nice error which shows you the different options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants