1- # Nebulex Distributed
1+ # Nebulex Distributed : spider_web :
22> Distributed cache topologies adapters for [ Nebulex] [ Nebulex ] .
33
4- [ Nebulex ] : https ://github.com/cabol /nebulex
4+ [ Nebulex ] : http ://github.com/elixir-nebulex /nebulex
55
6- ![ CI] ( https ://github.com/elixir-nebulex/nebulex_distributed/workflows/CI/badge.svg)
7- [ ![ Documentation ] ( https ://img.shields. io/badge/Documentation-ff69b4 )] ( https ://hexdocs.pm/ nebulex_distributed)
8- [ ![ Hex Version ] ( https ://img.shields.io/hexpm/v/nebulex_distributed.svg)] ( https ://hex.pm/packages/nebulex_distributed)
9- [ ![ Codecov ] ( https ://codecov. io/gh/elixir-nebulex/nebulex_distributed/graph/badge.svg )] ( https ://codecov.io/gh/elixir-nebulex/ nebulex_distributed/graph/badge.svg )
6+ ![ CI] ( http ://github.com/elixir-nebulex/nebulex_distributed/workflows/CI/badge.svg)
7+ [ ![ Codecov ] ( http ://codecov. io/gh/elixir-nebulex/nebulex_distributed/graph/badge.svg )] ( http ://codecov.io/gh/elixir-nebulex/ nebulex_distributed/graph/badge.svg )
8+ [ ![ Hex.pm ] ( http ://img.shields.io/hexpm/v/nebulex_distributed.svg)] ( http ://hex.pm/packages/nebulex_distributed)
9+ [ ![ Documentation ] ( http ://img.shields. io/badge/Documentation-ff69b4 )] ( http ://hexdocs.pm/ nebulex_distributed)
1010
11- See the [ online documentation] [ online_docs ] for more information.
11+ ## About
12+
13+ One of the goals of Nebulex is also to provide the ability to set up distributed
14+ cache topologies, but this feature will depend on the adapters. Here is where
15+ ** "Nebulex Distributed"** comes in. It provides the following adapters to set up
16+ distributed topologies:
1217
13- [ online_docs ] : https://hexdocs.pm/nebulex_distributed/
18+ * ` Nebulex.Adapters.Multilevel ` - Multi-level distributed cache topology.
19+ * ` Nebulex.Adapters.Partitioned ` - Partitioned cache topology.
20+ * ` Nebulex.Adapters.Replicated ` - Replicated cache topology (** WIP!** ).
21+
22+ These adapters work more as wrappers for an existing local adapter and provide
23+ the distributed topology on top of it. You can optionally set the adapter for
24+ the primary cache storage with the option ` :primary_storage_adapter ` .
1425
1526## Installation
1627
@@ -19,14 +30,14 @@ Add `:nebulex_distributed` to your list of dependencies in `mix.exs`:
1930``` elixir
2031def deps do
2132 [
22- {:nebulex_distributed , " ~> 3.0" }
33+ {:nebulex_distributed , " ~> 3.0.0-rc.1 " }
2334 ]
2435end
2536```
2637
27- ## Usage
38+ ## Partitioned cache topology example
2839
29- You can define a cache as follows:
40+ You can define a partitioned cache as follows:
3041
3142``` elixir
3243defmodule MyApp .PartitionedCache do
@@ -65,8 +76,69 @@ def start(_type, _args) do
6576end
6677```
6778
79+ ## Near cache topology example
80+
81+ To set up a near cache, you use the multilevel adapter, like so:
82+
83+ ``` elixir
84+ defmodule MyApp .Multilevel do
85+ use Nebulex .Cache ,
86+ otp_app: :nebulex ,
87+ adapter: Nebulex .Adapters .Multilevel
88+
89+ defmodule L1 do
90+ use Nebulex .Cache ,
91+ otp_app: :nebulex ,
92+ adapter: Nebulex .Adapters .Local
93+ end
94+
95+ defmodule L2 do
96+ use Nebulex .Cache ,
97+ otp_app: :nebulex ,
98+ adapter: Nebulex .Adapters .Partitioned
99+ end
100+ end
101+ ```
102+
103+ Where the configuration for the cache and its levels must be in your
104+ application environment, usually defined in your ` config/config.exs ` :
105+
106+ ``` elixir
107+ config :my_app , MyApp .Multilevel ,
108+ levels: [
109+ {
110+ MyApp .Multilevel .L1 ,
111+ gc_interval: :timer .hours (12 ),
112+ backend: :shards
113+ },
114+ {
115+ MyApp .Multilevel .L2 ,
116+ primary: [
117+ gc_interval: :timer .hours (12 ),
118+ backend: :shards
119+ ]
120+ }
121+ ]
122+ ```
123+
124+ If your application was generated with a supervisor (by passing ` --sup `
125+ to ` mix new ` ) you will have a ` lib/my_app/application.ex ` file containing
126+ the application start callback that defines and starts your supervisor.
127+ You just need to edit the ` start/2 ` function to start the cache as a
128+ supervisor on your application's supervisor:
129+
130+ ``` elixir
131+ def start (_type , _args ) do
132+ children = [
133+ {MyApp .Multilevel , []},
134+ .. .
135+ ]
136+ ```
137+
68138See the [ online documentation] [ online_docs ] for more information.
69139
140+ [ online_docs ] : http://hexdocs.pm/nebulex_distributed
141+
70142## Testing
71143
72144Since this adapter uses support modules and shared tests from ` Nebulex ` ,
@@ -110,38 +182,39 @@ You will find the coverage report within `cover/excoveralls.html`.
110182## Benchmarks
111183
112184The adapter provides a set of basic benchmark tests using the library
113- [ benchee] ( https ://github.com/PragTob/benchee) , and they are located within
185+ [ benchee] ( http ://github.com/PragTob/benchee) , and they are located within
114186the directory [ benchmarks] ( ./benchmarks ) .
115187
116188To run a benchmark test you have to run:
117189
118190```
119- $ MIX_ENV=test mix run benchmarks/{ BENCH_TEST_FILE}
191+ mix run benchmarks/BENCH_TEST_FILE
120192```
121193
122194Where ` BENCH_TEST_FILE ` can be any of:
123195
124196 * ` partitioned_bench.exs ` : benchmark for the partitioned adapter using
125197 the ` Nebulex.Adapters.Local ` as primary storage.
198+ * ` multilevel_bench.exs ` : benchmark for the multilevel adapter.
126199
127200## Contributing
128201
129202Contributions to Nebulex are very welcome and appreciated!
130203
131- Use the [ issue tracker] ( https ://github.com/elixir-nebulex/nebulex_distributed/issues)
204+ Use the [ issue tracker] ( http ://github.com/elixir-nebulex/nebulex_distributed/issues)
132205for bug reports or feature requests. Open a
133- [ pull request] ( https ://github.com/elixir-nebulex/nebulex_distributed/pulls)
206+ [ pull request] ( http ://github.com/elixir-nebulex/nebulex_distributed/pulls)
134207when you are ready to contribute.
135208
136209When submitting a pull request you should not update the
137210[ CHANGELOG.md] ( CHANGELOG.md ) , and also make sure you test your changes
138211thoroughly, include unit tests alongside new or changed code.
139212
140- Before to submit a PR it is highly recommended to run ` mix check ` and ensure
213+ Before to submit a PR it is highly recommended to run ` mix test.ci ` and ensure
141214all checks run successfully.
142215
143216## Copyright and License
144217
145218Copyright (c) 2024 Carlos Andres Bolaños R.A.
146219
147- ` Nebulex.Adapters.Local ` source code is licensed under the [ MIT License] ( LICENSE ) .
220+ ` nebulex_distributed ` source code is licensed under the [ MIT License] ( LICENSE ) .
0 commit comments