55[ Cachex ] : http://github.com/whitfin/cachex
66
77![ CI] ( http://github.com/elixir-nebulex/nebulex_adapters_cachex/workflows/CI/badge.svg )
8- [ ![ Codecov] ( http://codecov.io/gh/elixir-nebulex/nebulex_adapters_cachex/branch/v3.0.0-dev/ graph/badge.svg )] ( http://codecov.io/gh/elixir-nebulex/nebulex_adapters_cachex/branch/v3.0.0-dev /graph/badge.svg )
8+ [ ![ Codecov] ( http://codecov.io/gh/elixir-nebulex/nebulex_adapters_cachex/graph/badge.svg )] ( http://codecov.io/gh/elixir-nebulex/nebulex_adapters_cachex/branch/graph/badge.svg )
99[ ![ Hex Version] ( http://img.shields.io/hexpm/v/nebulex_adapters_cachex.svg )] ( http://hex.pm/packages/nebulex_adapters_cachex )
1010[ ![ Documentation] ( http://img.shields.io/badge/Documentation-ff69b4 )] ( http://hexdocs.pm/nebulex_adapters_cachex )
1111
12+ ## About
13+
14+ This adapter provides a Nebulex interface on top of [ Cachex] [ Cachex ] , a powerful
15+ in-memory caching library for Elixir. It combines Nebulex's unified caching API
16+ with Cachex's rich feature set.
17+
1218## Installation
1319
1420Add ` :nebulex_adapters_cachex ` to your list of dependencies in ` mix.exs ` :
@@ -26,7 +32,7 @@ for more information.
2632
2733## Usage
2834
29- You can define a cache using Cachex as follows :
35+ Define your cache:
3036
3137``` elixir
3238defmodule MyApp .Cache do
@@ -36,97 +42,64 @@ defmodule MyApp.Cache do
3642end
3743```
3844
39- Where the configuration for the cache must be in your application
40- environment, usually defined in your ` config/config.exs ` :
45+ Configure in your ` config/config.exs ` :
4146
4247``` elixir
4348config :my_app , MyApp .Cache ,
44- stats: true ,
45- .. .
49+ stats: true
4650```
4751
48- If your application was generated with a supervisor (by passing ` --sup `
49- to ` mix new ` ) you will have a ` lib/my_app/application.ex ` file containing
50- the application start callback that defines and starts your supervisor.
51- You just need to edit the ` start/2 ` function to start the cache as a
52- supervisor on your application's supervisor:
52+ Add to your application supervision tree:
5353
5454``` elixir
5555def start (_type , _args ) do
5656 children = [
5757 {MyApp .Cache , []},
58+ # ... other children
5859 ]
5960
60- .. .
61+ Supervisor . start_link (children, strategy: :one_for_one )
6162end
6263```
6364
64- Since Cachex uses macros for some configuration options, you could also
65- pass the options in runtime when the cache is started, either by calling
66- ` MyApp.Cache.start_link/1 ` directly, or in your app supervision tree:
65+ The adapter supports all Cachex options. See [ Cachex.start_link/2] [ cachex_start_link ]
66+ for configuration options including expiration, hooks, limits, and warmers.
6767
68- ``` elixir
69- def start (_type , _args ) do
70- children = [
71- {MyApp .Cache , cachex_opts ()},
72- ]
73-
74- .. .
75- end
76-
77- defp cachex_opts do
78- import Cachex .Spec
79-
80- [
81- expiration: expiration (
82- # how often cleanup should occur
83- interval: :timer .seconds (30 ),
84-
85- # default record expiration
86- default: :timer .seconds (60 ),
87-
88- # whether to enable lazy checking
89- lazy: true
90- ),
91-
92- .. .
93- ]
94- end
95- ```
96-
97- > See [ Cachex.start_link/2] [ cachex_start_link ] for more information
98- about the options.
68+ For more details and examples, see the [ module documentation] [ docs ] .
9969
10070[ cachex_start_link ] : http://hexdocs.pm/cachex/Cachex.html#start_link/2
71+ [ docs ] : http://hexdocs.pm/nebulex_adapters_cachex/Nebulex.Adapters.Cachex.html
72+
73+ ## Distributed Caching Topologies
10174
102- ## Distributed caching topologies
75+ The Cachex adapter works seamlessly with Nebulex's distributed adapters. Use it
76+ as a local cache in multi-level topologies or as primary storage for partitioned
77+ caches.
10378
104- Using the distributed adapters with ` Cachex ` as a primary storage is possible.
105- For example, let's define a multi-level cache (near cache topology), where
106- the L1 is a local cache using Cachex and the L2 is a partitioned cache.
79+ ** Example: Multi-level cache (near cache pattern)**
10780
10881``` elixir
10982defmodule MyApp .NearCache do
11083 use Nebulex .Cache ,
111- otp_app: :nebulex ,
84+ otp_app: :my_app ,
11285 adapter: Nebulex .Adapters .Multilevel
11386
11487 defmodule L1 do
11588 use Nebulex .Cache ,
116- otp_app: :nebulex ,
89+ otp_app: :my_app ,
11790 adapter: Nebulex .Adapters .Cachex
11891 end
11992
12093 defmodule L2 do
12194 use Nebulex .Cache ,
122- otp_app: :nebulex ,
95+ otp_app: :my_app ,
12396 adapter: Nebulex .Adapters .Partitioned ,
12497 primary_storage_adapter: Nebulex .Adapters .Cachex
12598 end
12699end
127100```
128101
129- And the configuration may look like :
102+ Configuration :
130103
131104``` elixir
132105config :my_app , MyApp .NearCache ,
@@ -137,16 +110,12 @@ config :my_app, MyApp.NearCache,
137110 ]
138111```
139112
140- > ** NOTE:** You could also use [ Nebulex.Adapters.Redis] [ nbx_redis_adapter ]
141- > for L2, it would be matter of changing the adapter for the L2 and the
142- > configuration for set up Redis adapter.
143-
144- See [ Nebulex examples] ( http://github.com/elixir-nebulex/nebulex_examples ) .
145- You will find examples for all different topologies, even using other adapters
146- like Redis; for all examples you just have to replace ` Nebulex.Adapters.Local `
147- by ` Nebulex.Adapters.Cachex ` .
113+ You can also use [ Nebulex.Adapters.Redis] [ nbx_redis_adapter ] for L2 to add
114+ persistence. See the [ module documentation] [ docs ] and
115+ [ Nebulex examples] [ nbx_examples ] for more topologies.
148116
149117[ nbx_redis_adapter ] : http://github.com/elixir-nebulex/nebulex_redis_adapter
118+ [ nbx_examples ] : http://github.com/elixir-nebulex/nebulex_examples
150119
151120## Testing
152121
@@ -161,7 +130,7 @@ to `nebulex`:
161130export NEBULEX_PATH=nebulex
162131```
163132
164- Second, make sure you fetch ` :nebulex ` dependency directly from GtiHub
133+ Second, make sure you fetch ` :nebulex ` dependency directly from GitHub
165134by running:
166135
167136```
@@ -212,11 +181,11 @@ When submitting a pull request you should not update the
212181[ CHANGELOG.md] ( CHANGELOG.md ) , and also make sure you test your changes
213182thoroughly, include unit tests alongside new or changed code.
214183
215- Before to submit a PR it is highly recommended to run ` mix test.ci ` and ensure
184+ Before submitting a PR it is highly recommended to run ` mix test.ci ` and ensure
216185all checks run successfully.
217186
218187## Copyright and License
219188
220189Copyright (c) 2020, Carlos Bolaños.
221190
222- Nebulex.Adapters.Cachex source code is licensed under the [ MIT License] ( LICENSE ) .
191+ Nebulex.Adapters.Cachex source code is licensed under the [ MIT License] ( LICENSE.md ) .
0 commit comments