Skip to content

Commit c85d6d8

Browse files
committed
[#7] Migrate adapter to Nebulex v3
1 parent a659dba commit c85d6d8

33 files changed

+1260
-627
lines changed

.credo.exs

Lines changed: 176 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,188 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
17
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
210
configs: [
311
%{
12+
#
13+
# Run any config using `mix credo -C <name>`. If no config name is given
14+
# "default" is used.
15+
#
416
name: "default",
17+
#
18+
# These are the files included in the analysis:
519
files: %{
6-
included: ["lib/", "src/", "test/", "benchmarks/"],
7-
excluded: [~r"/_build/", ~r"/deps/"]
20+
#
21+
# You can give explicit globs or simply directories.
22+
# In the latter case `**/*.{ex,exs}` will be used.
23+
#
24+
included: [
25+
"lib/",
26+
"src/",
27+
"test/",
28+
"benchmarks/",
29+
"web/",
30+
"apps/*/lib/",
31+
"apps/*/src/",
32+
"apps/*/test/",
33+
"apps/*/web/"
34+
],
35+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
836
},
37+
#
38+
# Load and configure plugins here:
39+
#
40+
plugins: [],
41+
#
42+
# If you create your own checks, you must specify the source files for
43+
# them here, so they can be loaded by Credo before running the analysis.
44+
#
45+
requires: [],
46+
#
47+
# If you want to enforce a style guide and need a more traditional linting
48+
# experience, you can change `strict` to `true` below:
49+
#
50+
strict: true,
51+
#
52+
# To modify the timeout for parsing files, change this value:
53+
#
54+
parse_timeout: 5000,
55+
#
56+
# If you want to use uncolored output by default, you can change `color`
57+
# to `false` below:
58+
#
959
color: true,
60+
#
61+
# You can customize the parameters of any check by adding a second element
62+
# to the tuple.
63+
#
64+
# To disable a check put `false` as second element:
65+
#
66+
# {Credo.Check.Design.DuplicatedCode, false}
67+
#
1068
checks: [
11-
# Readability Checks
12-
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
69+
#
70+
## Consistency Checks
71+
#
72+
{Credo.Check.Consistency.ExceptionNames, []},
73+
{Credo.Check.Consistency.LineEndings, []},
74+
{Credo.Check.Consistency.ParameterPatternMatching, []},
75+
{Credo.Check.Consistency.SpaceAroundOperators, []},
76+
{Credo.Check.Consistency.SpaceInParentheses, []},
77+
{Credo.Check.Consistency.TabsOrSpaces, []},
1378

14-
# TODO and FIXME do not cause the build to fail
15-
{Credo.Check.Design.TagTODO, exit_status: 0},
16-
{Credo.Check.Design.TagFIXME, exit_status: 0}
79+
#
80+
## Design Checks
81+
#
82+
# You can customize the priority of any check
83+
# Priority values are: `low, normal, high, higher`
84+
#
85+
{Credo.Check.Design.AliasUsage, [priority: :low]},
86+
# You can also customize the exit_status of each check.
87+
# If you don't want TODO comments to cause `mix credo` to fail, just
88+
# set this value to 0 (zero).
89+
#
90+
{Credo.Check.Design.TagTODO, [exit_status: 0]},
91+
{Credo.Check.Design.TagFIXME, [exit_status: 0]},
92+
93+
#
94+
## Readability Checks
95+
#
96+
{Credo.Check.Readability.AliasOrder, []},
97+
{Credo.Check.Readability.FunctionNames, []},
98+
{Credo.Check.Readability.LargeNumbers, []},
99+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 100]},
100+
{Credo.Check.Readability.ModuleAttributeNames, []},
101+
{Credo.Check.Readability.ModuleDoc, []},
102+
{Credo.Check.Readability.ModuleNames, []},
103+
{Credo.Check.Readability.ParenthesesInCondition, []},
104+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
105+
{Credo.Check.Readability.PredicateFunctionNames, []},
106+
{Credo.Check.Readability.PreferImplicitTry, []},
107+
{Credo.Check.Readability.RedundantBlankLines, []},
108+
{Credo.Check.Readability.Semicolons, []},
109+
{Credo.Check.Readability.SpaceAfterCommas, []},
110+
{Credo.Check.Readability.StringSigils, []},
111+
{Credo.Check.Readability.TrailingBlankLine, []},
112+
{Credo.Check.Readability.TrailingWhiteSpace, []},
113+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
114+
{Credo.Check.Readability.VariableNames, []},
115+
116+
#
117+
## Refactoring Opportunities
118+
#
119+
{Credo.Check.Refactor.CondStatements, []},
120+
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 40]},
121+
{Credo.Check.Refactor.FunctionArity, []},
122+
{Credo.Check.Refactor.LongQuoteBlocks, [max_line_count: 200]},
123+
# {Credo.Check.Refactor.MapInto, []},
124+
{Credo.Check.Refactor.MatchInCondition, []},
125+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
126+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
127+
{Credo.Check.Refactor.Nesting, []},
128+
{Credo.Check.Refactor.UnlessWithElse, []},
129+
{Credo.Check.Refactor.WithClauses, []},
130+
131+
#
132+
## Warnings
133+
#
134+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
135+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
136+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
137+
{Credo.Check.Warning.IExPry, []},
138+
{Credo.Check.Warning.IoInspect, []},
139+
# {Credo.Check.Warning.LazyLogging, []},
140+
{Credo.Check.Warning.MixEnv, false},
141+
{Credo.Check.Warning.OperationOnSameValues, []},
142+
{Credo.Check.Warning.OperationWithConstantResult, []},
143+
{Credo.Check.Warning.RaiseInsideRescue, []},
144+
{Credo.Check.Warning.UnusedEnumOperation, []},
145+
{Credo.Check.Warning.UnusedFileOperation, []},
146+
{Credo.Check.Warning.UnusedKeywordOperation, []},
147+
{Credo.Check.Warning.UnusedListOperation, []},
148+
{Credo.Check.Warning.UnusedPathOperation, []},
149+
{Credo.Check.Warning.UnusedRegexOperation, []},
150+
{Credo.Check.Warning.UnusedStringOperation, []},
151+
{Credo.Check.Warning.UnusedTupleOperation, []},
152+
{Credo.Check.Warning.UnsafeExec, []},
153+
154+
#
155+
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
156+
157+
#
158+
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
159+
#
160+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
161+
{Credo.Check.Consistency.UnusedVariableNames, false},
162+
{Credo.Check.Design.DuplicatedCode, false},
163+
{Credo.Check.Readability.AliasAs, false},
164+
{Credo.Check.Readability.BlockPipe, false},
165+
{Credo.Check.Readability.ImplTrue, false},
166+
{Credo.Check.Readability.MultiAlias, false},
167+
{Credo.Check.Readability.SeparateAliasRequire, false},
168+
{Credo.Check.Readability.SinglePipe, false},
169+
{Credo.Check.Readability.Specs, false},
170+
{Credo.Check.Readability.StrictModuleLayout, false},
171+
{Credo.Check.Readability.WithCustomTaggedTuple, false},
172+
{Credo.Check.Refactor.ABCSize, false},
173+
{Credo.Check.Refactor.AppendSingleItem, false},
174+
{Credo.Check.Refactor.DoubleBooleanNegation, false},
175+
{Credo.Check.Refactor.ModuleDependencies, false},
176+
{Credo.Check.Refactor.NegatedIsNil, false},
177+
{Credo.Check.Refactor.PipeChainStart, false},
178+
{Credo.Check.Refactor.VariableRebinding, false},
179+
{Credo.Check.Warning.LeakyEnvironment, false},
180+
{Credo.Check.Warning.MapGetUnsafePass, false},
181+
{Credo.Check.Warning.UnsafeToAtom, false}
182+
183+
#
184+
# Custom checks can be created using `mix credo.gen.check`.
185+
#
17186
]
18187
}
19188
]

.formatter.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Used by "mix format"
22
[
3-
inputs: ["{mix,.formatter}.exs", "{config,lib,test,benchmarks}/**/*.{ex,exs}"]
3+
import_deps: [:nebulex],
4+
inputs: ["{mix,.formatter}.exs", "{config,lib,test,benchmarks}/**/*.{ex,exs}"],
5+
line_length: 100
46
]

.github/workflows/ci.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@ on:
99
- main
1010

1111
jobs:
12-
nebulex_test:
12+
test:
1313
name: >-
14-
Nebulex.Adapters.Cachex Test (Elixir ${{ matrix.elixir }}
15-
/ OTP ${{ matrix.otp }} / OS ${{ matrix.os }})
14+
Nebulex.Adapters.Cachex Test (Elixir ${{ matrix.elixir }} /
15+
OTP ${{ matrix.otp }} /
16+
OS ${{ matrix.os }})
1617
runs-on: ${{ matrix.os }}
1718

1819
strategy:
1920
matrix:
2021
include:
21-
- elixir: 1.14.x
22-
otp: 25.x
22+
- elixir: 1.18.x
23+
otp: 27.x
2324
os: 'ubuntu-latest'
2425
style: true
2526
coverage: true
27+
sobelow: true
2628
dialyzer: true
27-
- elixir: 1.13.x
28-
otp: 24.x
29+
- elixir: 1.17.x
30+
otp: 26.x
31+
os: 'ubuntu-latest'
32+
- elixir: 1.16.x
33+
otp: 26.x
2934
os: 'ubuntu-latest'
30-
- elixir: 1.12.x
35+
- elixir: 1.15.x
36+
otp: 25.x
37+
os: 'ubuntu-latest'
38+
- elixir: 1.14.x
3139
otp: 23.x
3240
os: 'ubuntu-20.04'
3341

@@ -53,6 +61,8 @@ jobs:
5361
key: >-
5462
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{
5563
hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
64+
restore-keys: |
65+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
5666
5767
- name: Cache _build
5868
uses: actions/cache@v3
@@ -61,6 +71,8 @@ jobs:
6171
key: >-
6272
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build-${{
6373
hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
74+
restore-keys: |
75+
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build-
6476
6577
- name: Install Nebulex
6678
run: mix nbx.setup
@@ -98,7 +110,7 @@ jobs:
98110
id: plt-cache
99111
with:
100112
path: priv/plts
101-
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-v2
113+
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-v1
102114
if: ${{ matrix.dialyzer }}
103115

104116
- name: Create PLTs

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ erl_crash.dump
3737
/priv
3838
.sobelow*
3939
/nebulex
40+
Elixir*
41+
*.coverdata

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elixir 1.18.2-otp-27
2+
erlang 27.2.1

README.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add `:nebulex_adapters_cachex` to your list of dependencies in `mix.exs`:
2121
```elixir
2222
def deps do
2323
[
24-
{:nebulex_adapters_cachex, "~> 2.1"}
24+
{:nebulex_adapters_cachex, "~> 3.0"}
2525
]
2626
end
2727
```
@@ -43,7 +43,6 @@ environment, usually defined in your `config/config.exs`:
4343

4444
```elixir
4545
config :my_app, MyApp.Cache,
46-
limit: 1_000_000,
4746
stats: true,
4847
...
4948
```
@@ -82,42 +81,31 @@ defp cachex_opts do
8281

8382
[
8483
expiration: expiration(
85-
# default record expiration
86-
default: :timer.seconds(60),
87-
8884
# how often cleanup should occur
8985
interval: :timer.seconds(30),
9086

87+
# default record expiration
88+
default: :timer.seconds(60),
89+
9190
# whether to enable lazy checking
9291
lazy: true
9392
),
9493

95-
# complex limit
96-
limit: limit(
97-
size: 500,
98-
policy: Cachex.Policy.LRW,
99-
reclaim: 0.5,
100-
options: []
101-
),
102-
10394
...
10495
]
10596
end
10697
```
10798

108-
> See [Cachex.start_link/1][cachex_start_link] for more information
99+
> See [Cachex.start_link/2][cachex_start_link] for more information
109100
about the options.
110101

111-
[cachex_start_link]: https://hexdocs.pm/cachex/Cachex.html#start_link/1
102+
[cachex_start_link]: https://hexdocs.pm/cachex/Cachex.html#start_link/2
112103

113104
## Distributed caching topologies
114105

115-
In the same way we use the distributed adapters and the multilevel one to
116-
create distributed topologies, we can also do the same but instead of using
117-
the built-in local adapter using Cachex.
118-
119-
For example, let's define a multi-level cache (near cache topology), where
120-
the L1 is a local cache using Cachex and the L2 is a partitioned cache.
106+
Using the distributed adapters with `Cachex` as a primary storage is possible.
107+
For example, let's define a multi-level cache (near cache topology), where
108+
the L1 is a local cache using Cachex and the L2 is a partitioned cache.
121109

122110
```elixir
123111
defmodule MyApp.NearCache do
@@ -146,8 +134,8 @@ And the configuration may look like:
146134
config :my_app, MyApp.NearCache,
147135
model: :inclusive,
148136
levels: [
149-
{MyApp.NearCache.L1, [limit: 100_000]},
150-
{MyApp.NearCache.L2, primary: [limit: 1_000_000]}
137+
{MyApp.NearCache.L1, []},
138+
{MyApp.NearCache.L2, primary: [transactions: true]}
151139
]
152140
```
153141

@@ -164,9 +152,9 @@ by `Nebulex.Adapters.Cachex`.
164152

165153
## Testing
166154

167-
Since `Nebulex.Adapters.Cachex` uses the support modules and shared tests
168-
from `Nebulex` and by default its test folder is not included in the Hex
169-
dependency, the following steps are required for running the tests.
155+
Since this adapter uses support modules and shared tests from `Nebulex`,
156+
but the test folder is not included in the Hex dependency, the following
157+
steps are required to run the tests.
170158

171159
First of all, make sure you set the environment variable `NEBULEX_PATH`
172160
to `nebulex`:

0 commit comments

Comments
 (0)