Updating conCache's version to latest problems

We have this list of workers in lib/app.ex file.

  worker(ConCache, [[ttl_check: :timer.seconds(0.1), ttl: :timer.minutes(1)], [name: :camera_lock]], id: :camera_lock),
  worker(ConCache, [[ttl_check: :timer.seconds(1), ttl: :timer.hours(1)], [name: :users]], id: :users),
  worker(ConCache, [[ttl_check: :timer.seconds(1), ttl: :timer.hours(1)], [name: :camera]], id: :camera),
  worker(ConCache, [[ttl_check: :timer.seconds(1), ttl: :timer.hours(1)], [name: :cameras]], id: :cameras),
  worker(ConCache, [[ttl_check: :timer.seconds(1), ttl: :timer.hours(1)], [name: :camera_full]], id: :camera_full),
  worker(ConCache, [[ttl_check: :timer.hours(1), ttl: :timer.hours(24)], [name: :snapshot_error]], id: :snapshot_error),
  worker(ConCache, [[ttl_check: :timer.hours(2), ttl: :timer.hours(24)], [name: :camera_thumbnail]], id: :camera_thumbnail),
  worker(ConCache, [[ttl_check: :timer.hours(2), ttl: :timer.hours(24)], [name: :current_camera_status]], id: :current_camera_status),
  worker(ConCache, [[ttl_check: :timer.hours(2), ttl: :timer.hours(6)], [name: :camera_response_times]], id: :camera_response_times),

As lastest version of concache stated.

  • Added child_spec/1. A ConCache child can now be specified as {ConCache, [name: :my_cache, ttl_check_interval: false]}.

I tried changing very first one {ConCache,[ttl_check_interval: :timer.seconds(0.1), global_ttl: :timer.seconds(2.5), name: :cache]}
It works fine
but When I have other workers with an ID, it fails as when I did.

{ConCache, [ttl_check: :timer.seconds(0.1), ttl: :timer.seconds(1.5), name: :snapshot_schedule]},

It generated this error,

If using maps as child specifications, make sure the :id keys are unique.
If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

    children = [
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1),
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2)
    ]

** (Mix) Could not start application evercam_media: EvercamMedia.start(:normal, []) returned an error: bad child specification, more than one child specification has the id: ConCache.
If using maps as child specifications, make sure the :id keys are unique.
If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

    children = [
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1),
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2)
    ]

Can anyone tell if thats possible to still use it with an ID? which it seems not possible at this time?

Sorry

  {ConCache,[ttl_check_interval: :timer.seconds(0.1), global_ttl: :timer.seconds(2.5), name: :cache]},
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(0.1), global_ttl: :timer.seconds(1.5), name: :snapshot_schedule]}, id: :snapshot_schedule),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(0.1), global_ttl: :timer.minutes(1), name: :camera_lock]}, id: :camera_lock),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(1), global_ttl: :timer.hours(1), name: :users]}, id: :users),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(1), global_ttl: :timer.hours(1), name: :camera]}, id: :camera),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(1), global_ttl: :timer.hours(1), name: :cameras]}, id: :cameras),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.seconds(1), global_ttl: :timer.hours(1), name: :camera_full]}, id: :camera_full),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.hours(1), global_ttl: :timer.hours(24), name: :snapshot_error]}, id: :snapshot_error),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.hours(2), global_ttl: :timer.hours(24), name: :camera_thumbnail]}, id: :camera_thumbnail),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.hours(2), global_ttl: :timer.hours(24), name: :current_camera_status]}, id: :current_camera_status),
  Supervisor.child_spec({ConCache, [ttl_check_interval: :timer.hours(2), global_ttl: :timer.hours(6), name: :camera_response_times]}, id: :camera_response_times),

The answer is literally in the error message you get:

If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

children = [
  Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1),
  Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2)
]

The Elixir language tries to make the errors messages as useful as possible. If there’s something in the above error you think could be improved to make the solution clearer, I am sure a PR would be welcome.

1 Like

Yes thank you for the reply, It worked thanks.

Can you look this in the mean time? Concahe's weird behaviour on ConCache.get I am struggling with ConCache at the moment.

For note, the author of ConCache states that Cachex should probably be used for any new projects as it is more tested and feature-full, but he’ll keep using his for his own work as it’s pretty well customized for his use.