`Boruta.Cache` is started even when another `cache_backend` is configured

Open Beginner friendly
#80 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
elixir
Domain
backend

Research direction

Start at Boruta.Application.start/2 in lib/boruta/application.ex and inspect how Boruta.Config.cache_backend() selects the cache. Verify the application restart behavior with the new backend configuration, then update the Boruta.Config moduledoc and CHANGELOG as described; done means the configured alternative backend does not start Boruta.Cache while the default still does.

Written by the indexing model from the issue text.

Description

What is wrong

Boruta.Application.start/2 always starts Boruta.Cache (lib/boruta/application.ex on v2-3, unchanged on master):

children = [
  Boruta.Cache,
  {Finch, name: OpenIDHttpClient}
]

The cache_backend option exists so that a host application can bring its own backend, and the library honours it everywhere it caches: Boruta.Ecto.ClientStore, Boruta.Ecto.ScopeStore and Boruta.Ecto.TokenStore only ever call Boruta.Config.cache_backend(), and nothing else references Boruta.Cache. With another backend configured the Nebulex cache is therefore started, supervised and replicated for no caller.

What it costs

Boruta.Cache is a Nebulex.Adapters.Replicated cache. Started with a no-op cache_backend configured (Boruta 2.3.8, Nebulex 3.0.4, nebulex_distributed 3.2.3, OTP 29), its tree looks like this:

Processes under Boruta.Supervisor that belong to the cache 34 (inbox and outbox partition buffers, their task supervisors, the cluster monitor, the primary cache)
ETS tables named Boruta.Cache* 38, about 588 KiB
Process heaps of the cache tree about 333 KiB
Idle activity about 3,200 reductions per 5 s (the partition buffers tick every second)

Small in absolute terms, but on connected nodes the cluster monitor also joins the pg group and pushes a bootstrap of the (empty) cache to its peers on every start, and the host carries the nebulex, nebulex_local, nebulex_distributed, nebulex_streams, shards, ex_hash_ring and partitioned_buffer packages in its release for code it never calls.

Proposed fix (PR follows)

Start Boruta.Cache only when Boruta.Config.cache_backend() is Boruta.Cache. A host with another backend already has to start that backend itself, so nothing changes for it, and nothing changes for the default configuration. The PR adds the conditional in Boruta.Application, a sentence in the Boruta.Config moduledoc, a test that restarts the application with another backend, and a CHANGELOG entry. The patch applies unchanged to master.

Making nebulex an optional dependency, so that hosts with their own backend do not ship it at all, would be the next step; Boruta.Cache is defined with use Nebulex.Cache at compile time, so that is a separate change.

Dominant language
Elixir
Stars
97
Forks
23
Avg merge
8d 6h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from malach-it/boruta_auth

All issues in malach-it/boruta_auth

Similar issues

More Elixir issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.